Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1021: Expose sqlite3 metadata #1124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions deps/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ rm "$DOCS".bak
printf "$DEFINES" | sed -e "/^\s*$/d" >> "$DOCS"
printf "\`\`\`\n" >> "$DOCS"

# Run the script to update test files
$DEPS/download_update_tests.sh

echo "cleaning up..."
cd - > /dev/null || exit 1
rm -rf "$TEMP"
Expand Down
54 changes: 54 additions & 0 deletions deps/download_update_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

set -e

# This file is meant to be called by deps/download.sh but has been broken out for easy testing.

# Script scoped variables
TESTS="$(CDPATH= cd -- "$(dirname -- "$0")/../test" && pwd)"
DEPS="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"

echo "updating tests ..."

# Getting variables from sqlite3 source code
echo " getting values from sqlite3 code ..."
SQLITE_VARS="SQLITE_VERSION SQLITE_VERSION_NUMBER SQLITE_SOURCE_ID"
for SQLITE_VAR in $SQLITE_VARS; do
echo " getting $SQLITE_VAR from deps/sqlite3/sqlite3.c ..."
# Matches lines like:
# #define SQLITE_VERSION "3.44.2"
MATCH_STRING="^#define[ \t]+${SQLITE_VAR}[ \t]+\"?([^\"]*)\"?"
# Just print capture group of the value matched
REPLACE_STRING="\1"
# Dynamically initialize variable with given name to be the value
# matched in the sqlite3.c file.
declare $SQLITE_VAR="$(sed -n -E "s|$MATCH_STRING|$REPLACE_STRING|p" \
"$DEPS/sqlite3/sqlite3.c")"
done

# Validate all need variables are populated
REQUIRED_VARS="$SQLITE_VARS"
MISSING_VARS=""
for REQUIRED_VAR in $REQUIRED_VARS; do
if [ "${!REQUIRED_VAR}" = "" ]; then
MISSING_VARS="$MISSING_VARS $REQUIRED_VAR"
fi
done
if [ "$MISSING_VARS" != "" ]; then
echo "ERROR! The following required env. vars. are not defined: $MISSING_VARS"
exit 1
fi

# Do the file mutation
echo " editing test files ..."
echo " test/51.metadata.json ..."
for SQLITE_VAR in $SQLITE_VARS; do
echo " replacing $SQLITE_VAR with ${!SQLITE_VAR}"
# Matches JSON lines like:
# "SQLITE_VERSION": "3.44.2",
MATCH_STRING="\"$SQLITE_VAR\": (\"?)[^\",]*(\"?)(,?)$"
REPLACE_STRING="\"$SQLITE_VAR\": \1${!SQLITE_VAR}\2\3"
sed -E -i.bak \
-e "s|$MATCH_STRING|$REPLACE_STRING|g" \
"$TESTS/51.metadata.json"
done
5 changes: 5 additions & 0 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function Database(filenameGiven, options) {

Object.defineProperties(this, {
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
metadata: {
value: addon.metadata,
writable: false,
enumerable: true,
},
...wrappers.getters,
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"sqlite3": "^5.1.6"
},
"scripts": {
"install": "prebuild-install || node-gyp rebuild --release",
"install": "prebuild-install || npm run build-release",
"build-release": "node-gyp rebuild --release",
"build-debug": "node-gyp rebuild --debug",
"rebuild-release": "npm run lzz && npm run build-release",
Expand Down
56 changes: 56 additions & 0 deletions src/better_sqlite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,62 @@ NODE_MODULE_INIT(/* exports, context */) {
exports->Set(context, InternalizedFromLatin1(isolate, "Backup"), Backup::Init(isolate, data)).FromJust();
exports->Set(context, InternalizedFromLatin1(isolate, "setErrorConstructor"), v8::FunctionTemplate::New(isolate, Addon::JS_setErrorConstructor, data)->GetFunction(context).ToLocalChecked()).FromJust();

// Export sqlite3 metadata
v8::Local<v8::Object> metadata = v8::Object::New(isolate);
exports->Set(context, InternalizedFromLatin1(isolate, "metadata"), metadata).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_READONLY"), v8::Integer::New(isolate, SQLITE_OPEN_READONLY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_READWRITE"), v8::Integer::New(isolate, SQLITE_OPEN_READWRITE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_CREATE"), v8::Integer::New(isolate, SQLITE_OPEN_CREATE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_FULLMUTEX"), v8::Integer::New(isolate, SQLITE_OPEN_FULLMUTEX)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_URI"), v8::Integer::New(isolate, SQLITE_OPEN_URI)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_SHAREDCACHE"), v8::Integer::New(isolate, SQLITE_OPEN_SHAREDCACHE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_PRIVATECACHE"), v8::Integer::New(isolate, SQLITE_OPEN_PRIVATECACHE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_VERSION"), v8::String::NewFromUtf8(isolate, SQLITE_VERSION).ToLocalChecked()).FromJust();
#ifdef SQLITE_SOURCE_ID
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_SOURCE_ID"), v8::String::NewFromUtf8(isolate, SQLITE_SOURCE_ID).ToLocalChecked()).FromJust();
#endif
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_VERSION_NUMBER"), v8::Integer::New(isolate, SQLITE_VERSION_NUMBER)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_READWRITE"), v8::Integer::New(isolate, SQLITE_OPEN_READWRITE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OK"), v8::Integer::New(isolate, SQLITE_OK)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_ERROR"), v8::Integer::New(isolate, SQLITE_ERROR)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_INTERNAL"), v8::Integer::New(isolate, SQLITE_INTERNAL)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_PERM"), v8::Integer::New(isolate, SQLITE_PERM)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_ABORT"), v8::Integer::New(isolate, SQLITE_ABORT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_BUSY"), v8::Integer::New(isolate, SQLITE_BUSY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LOCKED"), v8::Integer::New(isolate, SQLITE_LOCKED)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOMEM"), v8::Integer::New(isolate, SQLITE_NOMEM)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_READONLY"), v8::Integer::New(isolate, SQLITE_READONLY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_INTERRUPT"), v8::Integer::New(isolate, SQLITE_INTERRUPT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_IOERR"), v8::Integer::New(isolate, SQLITE_IOERR)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_CORRUPT"), v8::Integer::New(isolate, SQLITE_CORRUPT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOTFOUND"), v8::Integer::New(isolate, SQLITE_NOTFOUND)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_FULL"), v8::Integer::New(isolate, SQLITE_FULL)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_CANTOPEN"), v8::Integer::New(isolate, SQLITE_CANTOPEN)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_PROTOCOL"), v8::Integer::New(isolate, SQLITE_PROTOCOL)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_EMPTY"), v8::Integer::New(isolate, SQLITE_EMPTY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_SCHEMA"), v8::Integer::New(isolate, SQLITE_SCHEMA)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_TOOBIG"), v8::Integer::New(isolate, SQLITE_TOOBIG)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_CONSTRAINT"), v8::Integer::New(isolate, SQLITE_CONSTRAINT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_MISMATCH"), v8::Integer::New(isolate, SQLITE_MISMATCH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_MISUSE"), v8::Integer::New(isolate, SQLITE_MISUSE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOLFS"), v8::Integer::New(isolate, SQLITE_NOLFS)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_AUTH"), v8::Integer::New(isolate, SQLITE_AUTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_FORMAT"), v8::Integer::New(isolate, SQLITE_FORMAT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_RANGE"), v8::Integer::New(isolate, SQLITE_RANGE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOTADB"), v8::Integer::New(isolate, SQLITE_NOTADB)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_LENGTH"), v8::Integer::New(isolate, SQLITE_LIMIT_LENGTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_SQL_LENGTH"), v8::Integer::New(isolate, SQLITE_LIMIT_SQL_LENGTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_COLUMN"), v8::Integer::New(isolate, SQLITE_LIMIT_COLUMN)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_EXPR_DEPTH"), v8::Integer::New(isolate, SQLITE_LIMIT_EXPR_DEPTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_COMPOUND_SELECT"), v8::Integer::New(isolate, SQLITE_LIMIT_COMPOUND_SELECT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_VDBE_OP"), v8::Integer::New(isolate, SQLITE_LIMIT_VDBE_OP)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_FUNCTION_ARG"), v8::Integer::New(isolate, SQLITE_LIMIT_FUNCTION_ARG)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_ATTACHED"), v8::Integer::New(isolate, SQLITE_LIMIT_ATTACHED)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_LIKE_PATTERN_LENGTH"), v8::Integer::New(isolate, SQLITE_LIMIT_LIKE_PATTERN_LENGTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_VARIABLE_NUMBER"), v8::Integer::New(isolate, SQLITE_LIMIT_VARIABLE_NUMBER)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_TRIGGER_DEPTH"), v8::Integer::New(isolate, SQLITE_LIMIT_TRIGGER_DEPTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_WORKER_THREADS"), v8::Integer::New(isolate, SQLITE_LIMIT_WORKER_THREADS)).FromJust();

// Store addon instance data.
addon->Statement.Reset(isolate, exports->Get(context, InternalizedFromLatin1(isolate, "Statement")).ToLocalChecked().As<v8::Function>());
addon->StatementIterator.Reset(isolate, exports->Get(context, InternalizedFromLatin1(isolate, "StatementIterator")).ToLocalChecked().As<v8::Function>());
Expand Down
56 changes: 56 additions & 0 deletions src/better_sqlite3.lzz
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,62 @@ NODE_MODULE_INIT(/* exports, context */) {
exports->Set(context, InternalizedFromLatin1(isolate, "Backup"), Backup::Init(isolate, data)).FromJust();
exports->Set(context, InternalizedFromLatin1(isolate, "setErrorConstructor"), v8::FunctionTemplate::New(isolate, Addon::JS_setErrorConstructor, data)->GetFunction(context).ToLocalChecked()).FromJust();

// Export sqlite3 metadata
v8::Local<v8::Object> metadata = v8::Object::New(isolate);
exports->Set(context, InternalizedFromLatin1(isolate, "metadata"), metadata).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_READONLY"), v8::Integer::New(isolate, SQLITE_OPEN_READONLY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_READWRITE"), v8::Integer::New(isolate, SQLITE_OPEN_READWRITE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_CREATE"), v8::Integer::New(isolate, SQLITE_OPEN_CREATE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_FULLMUTEX"), v8::Integer::New(isolate, SQLITE_OPEN_FULLMUTEX)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_URI"), v8::Integer::New(isolate, SQLITE_OPEN_URI)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_SHAREDCACHE"), v8::Integer::New(isolate, SQLITE_OPEN_SHAREDCACHE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_PRIVATECACHE"), v8::Integer::New(isolate, SQLITE_OPEN_PRIVATECACHE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_VERSION"), v8::String::NewFromUtf8(isolate, SQLITE_VERSION).ToLocalChecked()).FromJust();
#ifdef SQLITE_SOURCE_ID
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_SOURCE_ID"), v8::String::NewFromUtf8(isolate, SQLITE_SOURCE_ID).ToLocalChecked()).FromJust();
#endif
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_VERSION_NUMBER"), v8::Integer::New(isolate, SQLITE_VERSION_NUMBER)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OPEN_READWRITE"), v8::Integer::New(isolate, SQLITE_OPEN_READWRITE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_OK"), v8::Integer::New(isolate, SQLITE_OK)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_ERROR"), v8::Integer::New(isolate, SQLITE_ERROR)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_INTERNAL"), v8::Integer::New(isolate, SQLITE_INTERNAL)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_PERM"), v8::Integer::New(isolate, SQLITE_PERM)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_ABORT"), v8::Integer::New(isolate, SQLITE_ABORT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_BUSY"), v8::Integer::New(isolate, SQLITE_BUSY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LOCKED"), v8::Integer::New(isolate, SQLITE_LOCKED)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOMEM"), v8::Integer::New(isolate, SQLITE_NOMEM)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_READONLY"), v8::Integer::New(isolate, SQLITE_READONLY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_INTERRUPT"), v8::Integer::New(isolate, SQLITE_INTERRUPT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_IOERR"), v8::Integer::New(isolate, SQLITE_IOERR)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_CORRUPT"), v8::Integer::New(isolate, SQLITE_CORRUPT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOTFOUND"), v8::Integer::New(isolate, SQLITE_NOTFOUND)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_FULL"), v8::Integer::New(isolate, SQLITE_FULL)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_CANTOPEN"), v8::Integer::New(isolate, SQLITE_CANTOPEN)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_PROTOCOL"), v8::Integer::New(isolate, SQLITE_PROTOCOL)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_EMPTY"), v8::Integer::New(isolate, SQLITE_EMPTY)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_SCHEMA"), v8::Integer::New(isolate, SQLITE_SCHEMA)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_TOOBIG"), v8::Integer::New(isolate, SQLITE_TOOBIG)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_CONSTRAINT"), v8::Integer::New(isolate, SQLITE_CONSTRAINT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_MISMATCH"), v8::Integer::New(isolate, SQLITE_MISMATCH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_MISUSE"), v8::Integer::New(isolate, SQLITE_MISUSE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOLFS"), v8::Integer::New(isolate, SQLITE_NOLFS)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_AUTH"), v8::Integer::New(isolate, SQLITE_AUTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_FORMAT"), v8::Integer::New(isolate, SQLITE_FORMAT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_RANGE"), v8::Integer::New(isolate, SQLITE_RANGE)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_NOTADB"), v8::Integer::New(isolate, SQLITE_NOTADB)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_LENGTH"), v8::Integer::New(isolate, SQLITE_LIMIT_LENGTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_SQL_LENGTH"), v8::Integer::New(isolate, SQLITE_LIMIT_SQL_LENGTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_COLUMN"), v8::Integer::New(isolate, SQLITE_LIMIT_COLUMN)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_EXPR_DEPTH"), v8::Integer::New(isolate, SQLITE_LIMIT_EXPR_DEPTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_COMPOUND_SELECT"), v8::Integer::New(isolate, SQLITE_LIMIT_COMPOUND_SELECT)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_VDBE_OP"), v8::Integer::New(isolate, SQLITE_LIMIT_VDBE_OP)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_FUNCTION_ARG"), v8::Integer::New(isolate, SQLITE_LIMIT_FUNCTION_ARG)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_ATTACHED"), v8::Integer::New(isolate, SQLITE_LIMIT_ATTACHED)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_LIKE_PATTERN_LENGTH"), v8::Integer::New(isolate, SQLITE_LIMIT_LIKE_PATTERN_LENGTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_VARIABLE_NUMBER"), v8::Integer::New(isolate, SQLITE_LIMIT_VARIABLE_NUMBER)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_TRIGGER_DEPTH"), v8::Integer::New(isolate, SQLITE_LIMIT_TRIGGER_DEPTH)).FromJust();
metadata->Set(context, InternalizedFromLatin1(isolate, "SQLITE_LIMIT_WORKER_THREADS"), v8::Integer::New(isolate, SQLITE_LIMIT_WORKER_THREADS)).FromJust();

// Store addon instance data.
addon->Statement.Reset(isolate, exports->Get(context, InternalizedFromLatin1(isolate, "Statement")).ToLocalChecked().As<v8::Function>());
addon->StatementIterator.Reset(isolate, exports->Get(context, InternalizedFromLatin1(isolate, "StatementIterator")).ToLocalChecked().As<v8::Function>());
Expand Down
6 changes: 6 additions & 0 deletions test/12.database.pragma.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ describe('Database#pragma()', function () {
it('should return undefined if no rows exist and simpler results are desired', function () {
expect(this.db.pragma('table_info', { simple: true })).to.be.undefined;
});
// Added for issue: https://github.com/WiseLibs/better-sqlite3/issues/1021
it('should return sqlite3 compile_options', function () {
const compileOptionRows = this.db.pragma('compile_options')
const compileOption = compileOptionRows.map((x) => x.compile_options)
expect(compileOption).to.have.length(57)
});
});
16 changes: 16 additions & 0 deletions test/51.metadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const Database = require('../lib');
const snapshotData = require('./51.metadata.json');

describe('version', function () {
beforeEach(function () {
this.db = new Database(util.next());
});
afterEach(function () {
this.db.close();
});
// Added for issue: https://github.com/WiseLibs/better-sqlite3/issues/1021
it('can get metadata', function () {
expect(this.db.metadata).to.deep.equal(snapshotData['it can get metadata']);
});
});