From 01d99874a6d0620ea4f44cc049a1133ccae8ece0 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Wed, 16 Oct 2024 09:28:58 -0700 Subject: [PATCH] Omit features we don't use --- deps/defines.gypi | 7 ++- index.d.ts | 1 - lib/database.js | 1 - lib/methods/serialize.js | 16 ------- src/better_sqlite3.cpp | 33 -------------- src/better_sqlite3.hpp | 1 - test/37.database.serialize.js | 81 ----------------------------------- 7 files changed, 6 insertions(+), 134 deletions(-) delete mode 100644 lib/methods/serialize.js delete mode 100644 test/37.database.serialize.js diff --git a/deps/defines.gypi b/deps/defines.gypi index 84e7a3d..660c749 100644 --- a/deps/defines.gypi +++ b/deps/defines.gypi @@ -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', diff --git a/index.d.ts b/index.d.ts index 3f8c468..561757c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -93,7 +93,6 @@ declare namespace BetterSqlite3 { backup(destinationFile: string, options?: Database.BackupOptions): Promise; 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; } diff --git a/lib/database.js b/lib/database.js index cdd2edf..a10b96f 100644 --- a/lib/database.js +++ b/lib/database.js @@ -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'); diff --git a/lib/methods/serialize.js b/lib/methods/serialize.js deleted file mode 100644 index 4f1374f..0000000 --- a/lib/methods/serialize.js +++ /dev/null @@ -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); -}; diff --git a/src/better_sqlite3.cpp b/src/better_sqlite3.cpp index ec56b35..1dc1336 100644 --- a/src/better_sqlite3.cpp +++ b/src/better_sqlite3.cpp @@ -310,7 +310,6 @@ v8::Local 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 const& info) { if (!maybeBackup.IsEmpty()) info.GetReturnValue().Set(maybeBackup.ToLocalChecked()); } -void Database::JS_serialize(v8::FunctionCallbackInfo const& info) { - Database* db = node ::ObjectWrap ::Unwrap(info.This()); - if (info.Length() <= (0) || !info[0]->IsString()) - return ThrowTypeError( - "Expected " - "first" - " argument to be " - "a string"); - v8 ::Local attachedName = (info[0].As()); - 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(data), - length, FreeSerialization, NULL) - .ToLocalChecked()); -} void Database::JS_function(v8::FunctionCallbackInfo const& info) { Database* db = node ::ObjectWrap ::Unwrap(info.This()); if (info.Length() <= (0) || !info[0]->IsFunction()) diff --git a/src/better_sqlite3.hpp b/src/better_sqlite3.hpp index 4031882..363101e 100644 --- a/src/better_sqlite3.hpp +++ b/src/better_sqlite3.hpp @@ -188,7 +188,6 @@ class Database : public node::ObjectWrap { static void JS_prepare(v8::FunctionCallbackInfo const& info); static void JS_exec(v8::FunctionCallbackInfo const& info); static void JS_backup(v8::FunctionCallbackInfo const& info); - static void JS_serialize(v8::FunctionCallbackInfo const& info); static void JS_function(v8::FunctionCallbackInfo const& info); static void JS_aggregate(v8::FunctionCallbackInfo const& info); static void JS_table(v8::FunctionCallbackInfo const& info); diff --git a/test/37.database.serialize.js b/test/37.database.serialize.js deleted file mode 100644 index c459248..0000000 --- a/test/37.database.serialize.js +++ /dev/null @@ -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); - }); -});