Omit features we don't use
This commit is contained in:
parent
0da082ad0d
commit
01d99874a6
7
deps/defines.gypi
vendored
7
deps/defines.gypi
vendored
@ -6,10 +6,16 @@
|
||||
'SQLITE_DEFAULT_MEMSTATUS=0',
|
||||
'SQLITE_OMIT_AUTOINIT',
|
||||
'SQLITE_OMIT_DEPRECATED',
|
||||
'SQLITE_OMIT_DESERIALIZE',
|
||||
'SQLITE_OMIT_GET_TABLE',
|
||||
'SQLITE_OMIT_TCL_VARIABLE',
|
||||
'SQLITE_OMIT_PROGRESS_CALLBACK',
|
||||
'SQLITE_OMIT_SHARED_CACHE',
|
||||
'SQLITE_OMIT_UTF16',
|
||||
'SQLITE_OMIT_COMPLETE',
|
||||
'SQLITE_OMIT_GET_TABLE',
|
||||
'SQLITE_OMIT_AUTHORIZATION',
|
||||
'SQLITE_OMIT_LOAD_EXTENSION',
|
||||
'SQLITE_TRACE_SIZE_LIMIT=32',
|
||||
'SQLITE_DEFAULT_CACHE_SIZE=-16000',
|
||||
'SQLITE_DEFAULT_FOREIGN_KEYS=1',
|
||||
@ -22,7 +28,6 @@
|
||||
'SQLITE_ENABLE_STAT4',
|
||||
'SQLITE_ENABLE_FTS5',
|
||||
'SQLITE_ENABLE_JSON1',
|
||||
'SQLITE_ENABLE_RTREE',
|
||||
'SQLITE_INTROSPECTION_PRAGMAS',
|
||||
|
||||
'HAVE_STDINT_H=1',
|
||||
|
||||
1
index.d.ts
vendored
1
index.d.ts
vendored
@ -93,7 +93,6 @@ declare namespace BetterSqlite3 {
|
||||
backup(destinationFile: string, options?: Database.BackupOptions): Promise<Database.BackupMetadata>;
|
||||
table(name: string, options: VirtualTableOptions): this;
|
||||
unsafeMode(unsafe?: boolean): this;
|
||||
serialize(options?: Database.SerializeOptions): Buffer;
|
||||
createFTS5Tokenizer(name: string, tokenizer: FTS5TokenizerConstructor): void;
|
||||
signalTokenize(value: string): Array<string>;
|
||||
}
|
||||
|
||||
@ -80,7 +80,6 @@ Database.prototype.prepare = wrappers.prepare;
|
||||
Database.prototype.transaction = require('./methods/transaction');
|
||||
Database.prototype.pragma = require('./methods/pragma');
|
||||
Database.prototype.backup = require('./methods/backup');
|
||||
Database.prototype.serialize = require('./methods/serialize');
|
||||
Database.prototype.function = require('./methods/function');
|
||||
Database.prototype.aggregate = require('./methods/aggregate');
|
||||
Database.prototype.table = require('./methods/table');
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
'use strict';
|
||||
const { cppdb } = require('../util');
|
||||
|
||||
module.exports = function serialize(options) {
|
||||
if (options == null) options = {};
|
||||
|
||||
// Validate arguments
|
||||
if (typeof options !== 'object') throw new TypeError('Expected first argument to be an options object');
|
||||
|
||||
// Interpret and validate options
|
||||
const attachedName = 'attached' in options ? options.attached : 'main';
|
||||
if (typeof attachedName !== 'string') throw new TypeError('Expected the "attached" option to be a string');
|
||||
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
||||
|
||||
return this[cppdb].serialize(attachedName);
|
||||
};
|
||||
@ -310,7 +310,6 @@ v8::Local<v8 ::Function> Database::Init(v8::Isolate* isolate,
|
||||
SetPrototypeMethod(isolate, data, t, "prepare", JS_prepare);
|
||||
SetPrototypeMethod(isolate, data, t, "exec", JS_exec);
|
||||
SetPrototypeMethod(isolate, data, t, "backup", JS_backup);
|
||||
SetPrototypeMethod(isolate, data, t, "serialize", JS_serialize);
|
||||
SetPrototypeMethod(isolate, data, t, "function", JS_function);
|
||||
SetPrototypeMethod(isolate, data, t, "aggregate", JS_aggregate);
|
||||
SetPrototypeMethod(isolate, data, t, "table", JS_table);
|
||||
@ -683,38 +682,6 @@ void Database::JS_backup(v8::FunctionCallbackInfo<v8 ::Value> const& info) {
|
||||
if (!maybeBackup.IsEmpty())
|
||||
info.GetReturnValue().Set(maybeBackup.ToLocalChecked());
|
||||
}
|
||||
void Database::JS_serialize(v8::FunctionCallbackInfo<v8 ::Value> const& info) {
|
||||
Database* db = node ::ObjectWrap ::Unwrap<Database>(info.This());
|
||||
if (info.Length() <= (0) || !info[0]->IsString())
|
||||
return ThrowTypeError(
|
||||
"Expected "
|
||||
"first"
|
||||
" argument to be "
|
||||
"a string");
|
||||
v8 ::Local<v8 ::String> attachedName = (info[0].As<v8 ::String>());
|
||||
if (!db->open)
|
||||
return ThrowTypeError("The database connection is not open");
|
||||
if (db->busy)
|
||||
return ThrowTypeError("This database connection is busy executing a query");
|
||||
if (db->iterators)
|
||||
return ThrowTypeError("This database connection is busy executing a query");
|
||||
|
||||
v8 ::Isolate* isolate = info.GetIsolate();
|
||||
v8::String::Utf8Value attached_name(isolate, attachedName);
|
||||
sqlite3_int64 length = -1;
|
||||
unsigned char* data =
|
||||
sqlite3_serialize(db->db_handle, *attached_name, &length, 0);
|
||||
|
||||
if (!data && length) {
|
||||
ThrowError("Out of memory");
|
||||
return;
|
||||
}
|
||||
|
||||
info.GetReturnValue().Set(node::Buffer::New(isolate,
|
||||
reinterpret_cast<char*>(data),
|
||||
length, FreeSerialization, NULL)
|
||||
.ToLocalChecked());
|
||||
}
|
||||
void Database::JS_function(v8::FunctionCallbackInfo<v8 ::Value> const& info) {
|
||||
Database* db = node ::ObjectWrap ::Unwrap<Database>(info.This());
|
||||
if (info.Length() <= (0) || !info[0]->IsFunction())
|
||||
|
||||
@ -188,7 +188,6 @@ class Database : public node::ObjectWrap {
|
||||
static void JS_prepare(v8::FunctionCallbackInfo<v8 ::Value> const& info);
|
||||
static void JS_exec(v8::FunctionCallbackInfo<v8 ::Value> const& info);
|
||||
static void JS_backup(v8::FunctionCallbackInfo<v8 ::Value> const& info);
|
||||
static void JS_serialize(v8::FunctionCallbackInfo<v8 ::Value> const& info);
|
||||
static void JS_function(v8::FunctionCallbackInfo<v8 ::Value> const& info);
|
||||
static void JS_aggregate(v8::FunctionCallbackInfo<v8 ::Value> const& info);
|
||||
static void JS_table(v8::FunctionCallbackInfo<v8 ::Value> const& info);
|
||||
|
||||
@ -1,81 +0,0 @@
|
||||
'use strict';
|
||||
const Database = require('../.');
|
||||
|
||||
describe('Database#serialize()', function () {
|
||||
beforeEach(function () {
|
||||
this.db = new Database(util.next());
|
||||
this.db.prepare("CREATE TABLE entries (a TEXT, b INTEGER, c REAL, d BLOB, e TEXT)").run();
|
||||
this.seed = () => {
|
||||
this.db.prepare("INSERT INTO entries WITH RECURSIVE temp(a, b, c, d, e) AS (SELECT 'foo', 1, 3.14, x'dddddddd', NULL UNION ALL SELECT a, b + 1, c, d, e FROM temp LIMIT 1000) SELECT * FROM temp").run();
|
||||
};
|
||||
});
|
||||
afterEach(function () {
|
||||
this.db.close();
|
||||
});
|
||||
|
||||
it('should serialize the database and return a buffer', async function () {
|
||||
let buffer = this.db.serialize();
|
||||
expect(buffer).to.be.an.instanceof(Buffer);
|
||||
expect(buffer.length).to.be.above(1000);
|
||||
const lengthBefore = buffer.length;
|
||||
this.seed();
|
||||
buffer = this.db.serialize();
|
||||
expect(buffer).to.be.an.instanceof(Buffer);
|
||||
expect(buffer.length).to.be.above(lengthBefore);
|
||||
});
|
||||
it('should return a buffer that can be used by the Database constructor', async function () {
|
||||
this.seed();
|
||||
const buffer = this.db.serialize();
|
||||
expect(buffer).to.be.an.instanceof(Buffer);
|
||||
expect(buffer.length).to.be.above(1000);
|
||||
this.db.prepare('delete from entries').run();
|
||||
this.db.close();
|
||||
this.db = new Database(buffer);
|
||||
const bufferCopy = this.db.serialize();
|
||||
expect(buffer.length).to.equal(bufferCopy.length);
|
||||
expect(buffer).to.deep.equal(bufferCopy);
|
||||
this.db.prepare('insert into entries (rowid, a, b) values (?, ?, ?)').run(0, 'bar', -999);
|
||||
expect(this.db.prepare('select a, b from entries order by rowid limit 2').all())
|
||||
.to.deep.equal([{ a: 'bar', b: -999 }, { a: 'foo', b: 1 }]);
|
||||
});
|
||||
it('should accept the "attached" option', async function () {
|
||||
const smallBuffer = this.db.serialize();
|
||||
this.seed();
|
||||
const bigBuffer = this.db.serialize();
|
||||
this.db.close();
|
||||
this.db = new Database();
|
||||
this.db.prepare('attach ? as other').run(util.current());
|
||||
const smallBuffer2 = this.db.serialize();
|
||||
const bigBuffer2 = this.db.serialize({ attached: 'other' });
|
||||
expect(bigBuffer.length === bigBuffer2.length);
|
||||
expect(bigBuffer).to.deep.equal(bigBuffer2);
|
||||
expect(smallBuffer.length < bigBuffer.length);
|
||||
expect(smallBuffer2.length < bigBuffer.length);
|
||||
expect(smallBuffer).to.not.deep.equal(smallBuffer2);
|
||||
});
|
||||
it('should return a buffer that can be opened with the "readonly" option', async function () {
|
||||
this.seed();
|
||||
const buffer = this.db.serialize();
|
||||
expect(buffer).to.be.an.instanceof(Buffer);
|
||||
expect(buffer.length).to.be.above(1000);
|
||||
this.db.close();
|
||||
this.db = new Database(buffer, { readonly: true });
|
||||
expect(() => this.db.prepare('insert into entries (rowid, a, b) values (?, ?, ?)').run(0, 'bar', -999))
|
||||
.to.throw(Database.SqliteError);
|
||||
expect(this.db.prepare('select a, b from entries order by rowid limit 2').all())
|
||||
.to.deep.equal([{ a: 'foo', b: 1 }, { a: 'foo', b: 2 }]);
|
||||
const bufferCopy = this.db.serialize();
|
||||
expect(buffer.length).to.equal(bufferCopy.length);
|
||||
expect(buffer).to.deep.equal(bufferCopy);
|
||||
});
|
||||
it.skip('should work with an empty database', async function () {
|
||||
this.db.close();
|
||||
this.db = new Database();
|
||||
const buffer = this.db.serialize();
|
||||
expect(buffer).to.be.an.instanceof(Buffer);
|
||||
expect(buffer.length).to.equal(0);
|
||||
this.db.close();
|
||||
this.db = new Database(buffer);
|
||||
expect(this.db.serialize().length).to.equal(0);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user