Skip to content

Commit

Permalink
Merge pull request #2 from tutao/better-sqlcipher-new
Browse files Browse the repository at this point in the history
update Better sqlcipher
  • Loading branch information
ganthern authored Nov 20, 2023
2 parents e2c61e6 + a3e79dd commit 991676c
Show file tree
Hide file tree
Showing 40 changed files with 2,120 additions and 469 deletions.
9 changes: 8 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
* @JoshuaWise
/.github/workflows/build.yml @JoshuaWise @mceachen
/package.json @JoshuaWise @WiseLibs/better-sqlite3-team
/docs/compilation.md @JoshuaWise @WiseLibs/better-sqlite3-team
/docs/performance.md @JoshuaWise @WiseLibs/better-sqlite3-team
/docs/troubleshooting.md @JoshuaWise @WiseLibs/better-sqlite3-team
/deps/sqlite3/sqlite3.c @JoshuaWise @WiseLibs/better-sqlite3-team
/deps/sqlite3/sqlite3.h @JoshuaWise @WiseLibs/better-sqlite3-team
/deps/sqlite3/sqlite3ext.h @JoshuaWise @WiseLibs/better-sqlite3-team
/.github/workflows/build.yml @JoshuaWise @WiseLibs/better-sqlite3-team
57 changes: 41 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ jobs:
strategy:
matrix:
os:
- ubuntu-18.04
- ubuntu-20.04
- macos-latest
- windows-latest
- windows-2019
node:
- 10
- 12
- 14
- 16
- 18
name: Testing Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -58,7 +57,7 @@ jobs:
os:
- ubuntu-18.04
- macos-latest
- windows-latest
- windows-2019
name: Prebuild on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: publish
Expand All @@ -68,10 +67,12 @@ jobs:
with:
node-version: 16
- run: npm install --ignore-scripts
- run: npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
- run: npx --no-install prebuild -r electron -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 -t 17.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
- if: matrix.os == 'windows-latest'
run: npx --no-install prebuild -r electron -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 -t 17.0.0 --include-regex 'better_sqlite3.node$' --arch ia32 -u ${{ secrets.GITHUB_TOKEN }}
- run: npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
- run: npx --no-install prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
- if: matrix.os == 'windows-2019'
run: npx --no-install prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 --include-regex 'better_sqlite3.node$' --arch ia32 -u ${{ secrets.GITHUB_TOKEN }}
- if: matrix.os == 'macos-latest'
run: npx --no-install prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 --include-regex 'better_sqlite3.node$' --arch arm64 -u ${{ secrets.GITHUB_TOKEN }}

prebuild-alpine:
name: Prebuild on alpine
Expand All @@ -82,17 +83,41 @@ jobs:
- uses: actions/checkout@v2
- run: apk add build-base git python3 --update-cache
- run: npm install --ignore-scripts
- run: npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
- run: npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}

prebuild-alpine-arm:
strategy:
matrix:
arch:
- arm/v7
- arm64
name: Prebuild on alpine (${{ matrix.arch }})
runs-on: ubuntu-latest
needs: publish
steps:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- run: |
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:16-alpine -c "\
apk add build-base git python3 --update-cache && \
cd /tmp/project && \
npm install --ignore-scripts && \
npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}"
prebuild-arm64-alpine:
name: Prebuild on arm64 alpine
prebuild-linux-arm:
strategy:
matrix:
arch:
- arm/v7
- arm64
name: Prebuild on Linux (${{ matrix.arch }})
runs-on: ubuntu-latest
needs: publish
steps:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- run: |
docker run --rm --entrypoint /bin/sh --platform linux/arm64 node:16-alpine -c "apk add build-base git python3 --update-cache && \
git clone ${{ github.event.repository.clone_url }} && \
cd ${{ github.event.repository.name }} && \
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:16 -c "\
cd /tmp/project && \
npm install --ignore-scripts && \
npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}"
npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}"
36 changes: 36 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: bump-version

on:
workflow_dispatch:
inputs:
type:
type: choice
description: Type of version bump
required: true
options:
- patch
- minor
- major

jobs:
bump:
name: Bump to a new version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- uses: actions/setup-node@v2
with:
node-version: 16
- name: Configure user
run: |
git config --local user.name "${{ github.actor }}"
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
- name: Bump the version
run: npm version ${{ github.event.inputs.type }}
- name: Push commit
run: git push origin master:master
- name: Push tag
run: git push origin --tags
48 changes: 48 additions & 0 deletions .github/workflows/update-sqlite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: update-sqlite

on:
workflow_dispatch:
inputs:
year:
description: SQLite release year
required: true
version:
description: SQLite version (encoded)
required: true

jobs:
download-and-update:
name: Download and update SQLite
runs-on: ubuntu-latest
env:
ENV_YEAR: ${{ github.event.inputs.year }}
ENV_VERSION: ${{ github.event.inputs.version }}
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PAT }}
fetch-depth: 0
- uses: actions/setup-node@v2
with:
node-version: 16
- name: Create new update branch
run: git checkout -b sqlite-update-${{ env.ENV_VERSION }}
- name: Update download script
run: |
sed -Ei "s/YEAR=\"[0-9]+\"/YEAR=\"${{ env.ENV_YEAR }}\"/g" ./deps/download.sh
sed -Ei "s/VERSION=\"[0-9]+\"/VERSION=\"${{ env.ENV_VERSION }}\"/g" ./deps/download.sh
echo "ENV_TRUE_VERSION=$((10#${ENV_VERSION:0:1})).$((10#${ENV_VERSION:1:2})).$((10#${ENV_VERSION:3:2}))" >> $GITHUB_ENV
- name: Download, compile and package SQLite
run: npm run download
- name: Push update branch
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update SQLite to version ${{ env.ENV_TRUE_VERSION }}
branch: sqlite-update-${{ env.ENV_VERSION }}
- name: Create new PR
uses: repo-sync/pull-request@v2
with:
github_token: ${{ secrets.PAT }}
source_branch: sqlite-update-${{ env.ENV_VERSION }}
pr_title: Update SQLite to version ${{ env.ENV_TRUE_VERSION }}
pr_body: This is an automated pull request, updating SQLite to version \`${{ env.ENV_TRUE_VERSION }}\`.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ lib/binding
temp/
TODO
.local

# Downloaded artifact
deps/unverified.tmp
# deps/sqlcipher.tar.gz

.idea
25 changes: 25 additions & 0 deletions ACKNOWLEDGMENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Acknowledgments

## @types/better-sqlite3

MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The fastest and simplest library for SQLite3 in Node.js.
npm install better-sqlite3
```

> You must be using Node.js v10.20.1 or above. Prebuilt binaries are available for [LTS versions](https://nodejs.org/en/about/releases/). If you have trouble installing, check the [troubleshooting guide](./docs/troubleshooting.md).
> You must be using Node.js v14.21.1 or above. Prebuilt binaries are available for [LTS versions](https://nodejs.org/en/about/releases/). If you have trouble installing, check the [troubleshooting guide](./docs/troubleshooting.md).
## Usage

Expand All @@ -43,11 +43,18 @@ const row = db.prepare('SELECT * FROM users WHERE id = ?').get(userId);
console.log(row.firstName, row.lastName, row.email);
```

Though not required, [it is generally important to set the WAL pragma for performance reasons](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/performance.md).

```js
db.pragma('journal_mode = WAL');
```

##### In ES6 module notation:

```js
import Database from 'better-sqlite3';
const db = new Database('foobar.db', options);
db.pragma('journal_mode = WAL');
```

## Why should I use this instead of [node-sqlite3](https://github.com/mapbox/node-sqlite3)?
Expand Down Expand Up @@ -76,7 +83,9 @@ For these situations, you should probably use a full-fledged RDBMS such as [Post
- [64-bit integer support](./docs/integer.md)
- [Worker thread support](./docs/threads.md)
- [Unsafe mode (advanced)](./docs/unsafe.md)
- [SQLite3 compilation](./docs/compilation.md)
- [SQLite3 compilation (advanced)](./docs/compilation.md)
- [Contribution rules](./docs/contribution.md)
- [Code of conduct](./docs/conduct.md)

# License

Expand Down
12 changes: 7 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
'dependencies': ['deps/sqlite3.gyp:sqlite3'],
'sources': ['src/better_sqlite3.cpp'],
'cflags_cc': ['-std=c++17'],
'msvs-settings': {
'VCCLCompilerTool': {
'AdditionalOptions': ['-std:c++17']
}
},
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': ['-std=c++17', '-stdlib=libc++'],
},
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
'/std:c++17',
],
},
},
'conditions': [
['OS=="linux"', {
'ldflags': [
Expand Down
9 changes: 9 additions & 0 deletions deps/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
},
},
'conditions': [
['target_arch == "x64"', {
'variables': {
'rust_arch%': 'x86_64',
}
}, {
'variables': {
'rust_arch%': 'aarch64',
}
}],
['OS == "win"', {
'defines': ['WIN32'],
'variables': {
Expand Down
26 changes: 26 additions & 0 deletions deps/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const path = require('path');
const fs = require('fs');

const dest = process.argv[2];
const source = path.resolve(path.sep, process.argv[3] || path.join(__dirname, 'sqlite3'));
const files = [
{ filename: 'sqlite3.c', optional: false },
{ filename: 'sqlite3.h', optional: false },
];

if (process.argv[3]) {
// Support "_HAVE_SQLITE_CONFIG_H" in custom builds.
files.push({ filename: 'config.h', optional: true });
} else {
// Required for some tests.
files.push({ filename: 'sqlite3ext.h', optional: false });
}

for (const { filename, optional } of files) {
if (optional && !fs.existsSync(path.join(source, filename))) {
continue;
}
fs.accessSync(path.join(source, filename));
fs.copyFileSync(path.join(source, filename), path.join(dest, filename));
}
6 changes: 4 additions & 2 deletions deps/defines.gypi
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# THIS FILE IS AUTOMATICALLY GENERATED (DO NOT EDIT)

{
'defines': [
'SQLITE_LIKE_DOESNT_MATCH_BLOBS',
'SQLITE_THREADSAFE=2',
'SQLITE_USE_URI=0',
'SQLITE_DEFAULT_MEMSTATUS=0',
'SQLITE_OMIT_AUTOINIT',
'SQLITE_OMIT_DEPRECATED',
'SQLITE_OMIT_GET_TABLE',
'SQLITE_OMIT_TCL_VARIABLE',
Expand All @@ -15,6 +14,7 @@
'SQLITE_DEFAULT_CACHE_SIZE=-16000',
'SQLITE_DEFAULT_FOREIGN_KEYS=1',
'SQLITE_DEFAULT_WAL_SYNCHRONOUS=1',
'SQLITE_DQS=0',
'SQLITE_ENABLE_MATH_FUNCTIONS',
'SQLITE_ENABLE_DESERIALIZE',
'SQLITE_ENABLE_COLUMN_METADATA',
Expand All @@ -30,6 +30,8 @@
'HAVE_INT16_T=1',
'HAVE_INT32_T=1',
'HAVE_UINT8_T=1',
'HAVE_INT8_T=1',
'HAVE_STDINT_H=1',
'HAVE_UINT16_T=1',
'HAVE_UINT32_T=1',

Expand Down
Loading

0 comments on commit 991676c

Please sign in to comment.