sql-js / sql-js/sql.js

Uncaught TypeError: must start with number, buffer, array or string

Open
#134 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

I've created a little script with sql.js documentation, but i'm unable to write buffer into a.db (Win)
console gives me error: "Uncaught TypeError: must start with number, buffer, array or string"
is that something regarding "var data = db.export();" function or is there something wrong in my code?

var fs = require("fs");
var remote = require('remote');
var SQL = remote.require('sql.js');
var file = "a.db"
var exists = fs.existsSync(file);

if(!exists) {
console.log("DB creation: "+file+ "");
fs.openSync(file, "w");
}

var filebuffer = fs.readFileSync(file);

// Load the db
var db = new SQL.Database(filebuffer);
// Run a query without reading the results
db.run("CREATE TABLE test (col1, col2);");
// Insert two rows: (1,111) and (2,222)
db.run("INSERT INTO test VALUES (?,?), (?,?)", [1,111,2,222]);

var data = db.export();
var buffer = new Buffer(data);
fs.writeFileSync(file, buffer);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shown JavaScript script, focusing on the SQL.Database input and the conversion of db.export() before fs.writeFileSync. Reproduce the TypeError on Windows and verify that the script can create, write, and reopen a.db without the error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, sqlite
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.