Skip to content

Commit 2369516

Browse files
author
Christopher J. Brody
committed
Merge tag 'v1.8.0' of https://github.com/sql-js/sql.js
SQLite 3.38 add aggregate functions - maybe not wanted in this fork pull more updates from 2021, 2022, etc. keep FTS4 & JSON enabled with explicit flags continue to keep extension functions out of this fork
2 parents ea30bce + 12d3603 commit 2369516

31 files changed

+2683
-1388
lines changed

.devcontainer/Dockerfile

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# We build our DevContainer on MS' Typescript-Node Devcontainer
2+
# This gives us lots of standard stuff, and lets us layer a few custom things on top, like the Emscripten compiler, Puppeteer
3+
4+
# --------------------------------------------------------------------
5+
# BEGIN Standard MS Devcontainer for Typescript-Node
6+
7+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/typescript-node/.devcontainer/base.Dockerfile
8+
# [Choice] Node.js version: 14, 12, 10
9+
ARG VARIANT="14-buster"
10+
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
11+
12+
# [Optional] Uncomment if you want to install an additional version of node using nvm
13+
# ARG EXTRA_NODE_VERSION=10
14+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
15+
16+
# [Optional] Uncomment if you want to install more global node packages
17+
# RUN su node -c "npm install -g <your-package-list -here>"
18+
19+
# END Standard MS Devcontainer for Typescript-Node
20+
# --------------------------------------------------------------------
21+
22+
# --------------------------------------------------------------------
23+
# BEGIN EMSDK
24+
# Install EMSDK to /emsdk just like the EMSDK Dockerfile: https://github.com/emscripten-core/emsdk/blob/master/docker/Dockerfile
25+
ENV EMSDK /emsdk
26+
# We pin the EMSDK version rather than 'latest' so that everyone is using the same compiler version
27+
ENV EMSCRIPTEN_VERSION 3.1.20
28+
29+
RUN git clone https://github.com/emscripten-core/emsdk.git $EMSDK
30+
31+
RUN echo "## Install Emscripten" \
32+
&& cd ${EMSDK} \
33+
&& ./emsdk install ${EMSCRIPTEN_VERSION} \
34+
&& echo "## Done"
35+
36+
# Copied directly from https://github.com/emscripten-core/emsdk/blob/master/docker/Dockerfile
37+
RUN cd ${EMSDK} \
38+
&& echo "## Generate standard configuration" \
39+
&& ./emsdk activate ${EMSCRIPTEN_VERSION} \
40+
&& chmod 777 ${EMSDK}/upstream/emscripten \
41+
&& chmod -R 777 ${EMSDK}/upstream/emscripten/cache \
42+
&& echo "int main() { return 0; }" > hello.c \
43+
&& ${EMSDK}/upstream/emscripten/emcc -c hello.c \
44+
&& cat ${EMSDK}/upstream/emscripten/cache/sanity.txt \
45+
&& echo "## Done"
46+
47+
ENV PATH $EMSDK:$EMSDK/upstream/emscripten/:$PATH
48+
49+
# Cleanup Emscripten installation and strip some symbols
50+
# Copied directly from https://github.com/emscripten-core/emsdk/blob/master/docker/Dockerfile
51+
RUN echo "## Aggressive optimization: Remove debug symbols" \
52+
&& cd ${EMSDK} && . ./emsdk_env.sh \
53+
# Remove debugging symbols from embedded node (extra 7MB)
54+
&& strip -s `which node` \
55+
# Tests consume ~80MB disc space
56+
&& rm -fr ${EMSDK}/upstream/emscripten/tests \
57+
# Fastcomp is not supported
58+
&& rm -fr ${EMSDK}/upstream/fastcomp \
59+
# strip out symbols from clang (~extra 50MB disc space)
60+
&& find ${EMSDK}/upstream/bin -type f -exec strip -s {} + || true \
61+
&& echo "## Done"
62+
63+
RUN echo ". /emsdk/emsdk_env.sh" >> /etc/bash.bashrc
64+
# We must set the EM_NODE_JS environment variable for a somewhat silly reason
65+
# We run our build scripts with `npm run`, which sets the NODE environment variable as it runs.
66+
# The EMSDK picks up on that environment variable and gives a deprecation warning: warning: honoring legacy environment variable `NODE`. Please switch to using `EM_NODE_JS` instead`
67+
# So, we are going to put this environment variable here explicitly to avoid the deprecation warning.
68+
RUN echo 'export EM_NODE_JS="$EMSDK_NODE"' >> /etc/bash.bashrc
69+
70+
# END EMSDK
71+
# --------------------------------------------------------------------
72+
73+
# --------------------------------------------------------------------
74+
# BEGIN PUPPETEER dependencies
75+
# Here we install all of the packages depended upon by Chrome (that Puppeteer will use for headless tests).
76+
# We could also take a page from https://github.com/buildkite/docker-puppeteer/blob/master/Dockerfile instead,
77+
# and install the latest stable version of Chrome to get the right dependencies, but that version changes over time,
78+
# so the stable version of Chrome and the version installed by Puppeteer might diverge over time.
79+
# It also means they end up having Chrome downloaded and installed twice.
80+
# We could install the particular version of Chrome that our version of Puppeteer would use and then tell Puppeteer not to download its own version of Chrome,
81+
# but then we'd have to rebuild our Docker container every time we revved Puppeteer, and that feels fiddly too.
82+
# For all of these reasons, it seems safer to simply install the explicit list packages depended upon by Chrome, assume that's unlikely to change
83+
# and move on.
84+
85+
# List taken from:
86+
# https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix
87+
RUN apt-get update \
88+
&& apt-get install -y \
89+
ca-certificates \
90+
fonts-liberation \
91+
libappindicator3-1 \
92+
libasound2 \
93+
libatk-bridge2.0-0 \
94+
libatk1.0-0 \
95+
libc6 \
96+
libcairo2 \
97+
libcups2 \
98+
libdbus-1-3 \
99+
libexpat1 \
100+
libfontconfig1 \
101+
libgbm1 \
102+
libgcc1 \
103+
libglib2.0-0 \
104+
libgtk-3-0 \
105+
libnspr4 \
106+
libnss3 \
107+
libpango-1.0-0 \
108+
libpangocairo-1.0-0 \
109+
libstdc++6 \
110+
libx11-6 \
111+
libx11-xcb1 \
112+
libxcb1 \
113+
libxcomposite1 \
114+
libxcursor1 \
115+
libxdamage1 \
116+
libxext6 \
117+
libxfixes3 \
118+
libxi6 \
119+
libxrandr2 \
120+
libxrender1 \
121+
libxss1 \
122+
libxtst6 \
123+
lsb-release \
124+
wget \
125+
xdg-utils
126+
127+
# Installs the command "sha3sum", which is used check the download integrity of sqlite source.
128+
RUN apt-get install -y libdigest-sha3-perl
129+
130+
# We set this env variable (RUN_WORKER_TEST_WITHOUT_PUPPETEER_SANDBOX=1) this to tell our sql.js test harness to run Puppeteer without the sandbox.
131+
# Otherwise, when we instantiate Puppeteer, we get this error:
132+
# Puppeteer can't start due to a sandbox error. (Details follow.)
133+
# [0321/173044.694524:FATAL:zygote_host_impl_linux.cc(117)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.
134+
ENV RUN_WORKER_TEST_WITHOUT_PUPPETEER_SANDBOX=1
135+
136+
# END PUPPETEER
137+
# --------------------------------------------------------------------

.devcontainer/devcontainer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/typescript-node
3+
{
4+
"name": "Node.js & TypeScript",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
// Update 'VARIANT' to pick a Node version: 10, 12, 14
8+
"args": {
9+
"VARIANT": "14-buster"
10+
},
11+
},
12+
// Set *default* container specific settings.json values on container create.
13+
"settings": {},
14+
// Add the IDs of extensions you want installed when the container is created.
15+
"extensions": [
16+
"dbaeumer.vscode-eslint"
17+
],
18+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
19+
// "forwardPorts": [],
20+
// Use 'postCreateCommand' to run commands after the container is created.
21+
// We use `npm ci` instead of `npm install` because we want to respect the lockfile and ONLY the lockfile.
22+
// That way, our devcontainer is more reproducible. --Taytay
23+
"postCreateCommand": "npm ci",
24+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
25+
"remoteUser": "node"
26+
}

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
ignorePatterns: [
1717
"/dist/",
1818
"/examples/",
19+
"/documentation/",
1920
"/node_modules/",
2021
"/out/",
2122
"/src/shell-post.js",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# action.yml
2+
name: 'Build SQL.js'
3+
description: 'Builds sql.js using the .devcontainer/Dockerfile as its environment'
4+
runs:
5+
using: 'docker'
6+
image: '../../../.devcontainer/Dockerfile'
7+
entrypoint: "/github/workspace/.github/actions/build-sqljs/entrypoint.sh"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
cd /github/workspace/
6+
npm run rebuild

.github/workflows/CI.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v2
10-
- uses: actions/cache@v1
11-
id: cache
12-
with:
13-
path: '.emsdk-cache'
14-
key: emscripten-1.39.20
15-
- uses: mymindstorm/setup-emsdk@2a4a91b
16-
with:
17-
version: '1.39.20'
18-
actions-cache-folder: '.emsdk-cache'
1910
- name: make
20-
run: make
11+
uses: ./.github/actions/build-sqljs
2112
- uses: actions/upload-artifact@v2
2213
with: {name: dist, path: dist}
2314
- name: test
2415
run: npm ci && npm test
16+
- name: generate documentation
17+
run: npm run doc
18+
- name: Update github pages
19+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
20+
uses: JamesIves/github-pages-deploy-action@3.6.2
21+
with:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
BRANCH: gh-pages # The branch the action should deploy to.
24+
FOLDER: "." # The folder the action should deploy.
25+
CLEAN: false # Automatically remove deleted files from the deploy branch

.github/workflows/release.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15-
- uses: mymindstorm/setup-emsdk@2a4a91b
16-
with: {version: '1.39.20'}
1715
- name: make
18-
run: make
16+
uses: ./.github/actions/build-sqljs
1917
- name: Create Release
2018
id: create_release
2119
uses: actions/create-release@v1.0.0
@@ -28,7 +26,7 @@ jobs:
2826
prerelease: false
2927
- run: cd dist && zip sqljs-wasm.zip sql-wasm.{js,wasm}
3028
- name: Upload Release Asset (wasm)
31-
uses: lovasoa/upload-release-asset@851d9cc
29+
uses: lovasoa/upload-release-asset@851d9cc59fe8113912edffbd8fddaa09470a5ac0
3230
env:
3331
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3432
with:
@@ -38,7 +36,7 @@ jobs:
3836
asset_label: wasm version, best runtime performance, smaller assets, requires configuration
3937
asset_content_type: application/zip
4038
- name: Upload Release Asset (asm)
41-
uses: lovasoa/upload-release-asset@851d9cc
39+
uses: lovasoa/upload-release-asset@851d9cc59fe8113912edffbd8fddaa09470a5ac0
4240
env:
4341
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4442
with:
@@ -49,7 +47,7 @@ jobs:
4947
asset_content_type: text/javascript
5048
- run: cd dist && zip sqljs-worker-wasm.zip worker.sql-wasm.js sql-wasm.wasm
5149
- name: Upload Release Asset (worker wasm)
52-
uses: lovasoa/upload-release-asset@851d9cc
50+
uses: lovasoa/upload-release-asset@851d9cc59fe8113912edffbd8fddaa09470a5ac0
5351
env:
5452
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5553
with:
@@ -59,7 +57,7 @@ jobs:
5957
asset_label: webworker wasm version, to be loaded as a web worker
6058
asset_content_type: application/zip
6159
- name: Upload Release Asset (worker asm)
62-
uses: lovasoa/upload-release-asset@851d9cc
60+
uses: lovasoa/upload-release-asset@851d9cc59fe8113912edffbd8fddaa09470a5ac0
6361
env:
6462
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6563
with:
@@ -70,7 +68,7 @@ jobs:
7068
asset_content_type: text/javascript
7169
- run: cd dist && zip sqljs-all.zip *.{js,wasm}
7270
- name: Upload Release Asset (all)
73-
uses: lovasoa/upload-release-asset@851d9cc
71+
uses: lovasoa/upload-release-asset@851d9cc59fe8113912edffbd8fddaa09470a5ac0
7472
env:
7573
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7674
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules/
44
# Intermediary files:
55
cache/
66
out/
7+
.emsdk-cache/
78
sqlite-src/
89
tmp/
910
c/

.jsdoc.config.json

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,33 @@
66
"include": [
77
"src/api.js"
88
]
9+
},
10+
"opts": {
11+
"encoding": "utf8",
12+
"destination": "./documentation/",
13+
"readme": "documentation_index.md",
14+
"template": "./node_modules/clean-jsdoc-theme",
15+
"theme_opts": {
16+
"title": "sql.js",
17+
"meta": [
18+
"<title>sql.js API documentation</title>",
19+
"<meta name=\"author\" content=\"Ophir Lojkine\">",
20+
"<meta name=\"description\" content=\"Documentation for sql.js: an in-memory SQL database for the browser based on SQLite.\">"
21+
],
22+
"menu": [
23+
{
24+
"title": "Website",
25+
"link": "https://sql.js.org/"
26+
},
27+
{
28+
"title": "Github",
29+
"link": "https://github.com/sql-js/sql.js"
30+
},
31+
{
32+
"title": "Demo",
33+
"link": "https://sql.js.org/examples/GUI/"
34+
}
35+
]
36+
}
937
}
10-
}
38+
}

.nojekyll

Whitespace-only changes.

CONTRIBUTING.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
# Compiling and Contributing
3+
4+
General consumers of this library don't need to read any further. (The compiled files are available via the [release page](https://github.com/sql-js/sql.js/releases).)
5+
6+
If you want to compile your own version of SQLite for WebAssembly, or want to contribute to this project, read on.
7+
8+
## Setting up your Development Environment
9+
10+
### Containerized Development Environment (Recommended)
11+
12+
This project defines a standardized development environment using Docker (and the .devcontainer spec in particular). This allows for anyone on any platform to get up and running quickly. (VSCode is not technically required to make use of this standardized environment, but it makes containerized development so seamless that the non-VSCode path is not currently documented here.)
13+
14+
Standardizing our development environment has numerous benefits:
15+
- Allows anyone on ANY platform (Linux, Mac, and Windows) to contribute or compile their own build.
16+
- It's quicker and easier for any contributor to dive in and fix issues.
17+
- (Practically) eliminates configuration bugs that are difficult for maintainers to reproduce. Also known as "works on my machine" issues.
18+
- Allows us to write our scripts assuming that they're _always_ running in a single known environment of a single, known platform.
19+
- Ensure that all contributors use a known, standardized installation of EMSDK.
20+
- Allows for a more clearly documented process for updating the EMSDK to a new version.
21+
- End-Users that simply want to compile and install their own version of SQLite don't have to bother with EMSDK installation in their particular environment.
22+
23+
To get started:
24+
25+
1. Follow the [Installation Steps for Containerized Development in VSCode](https://code.visualstudio.com/docs/remote/containers#_installation). This includes installing Docker, VSCode, and the [Remote Development extension pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) for VSCode)
26+
2. Clone this repository
27+
3. Open the repository folder in VSCode. It will detect the presence of a .devcontainer and prompt you: "Folder contains a Dev Container configuration file. Reopen folder to develop in a container." Click "Reopen in container"
28+
29+
You're now ready to test the dev environment:
30+
31+
4. Click on Terminal->New Terminal to be dropped into a terminal inside the dev environment.
32+
5. Run `$ npm install` to install the required modules
33+
6. Run `$ npm test` to ensure all tests pass
34+
7. Run `$ npm rebuild` to re-compile the project from scratch (using the version of EMSDK installed in the container).
35+
8. Run `$ npm test` to ensure all tests pass after said rebuild
36+
37+
You're now ready for development!
38+
39+
### Host-based configuration (Not recommended)
40+
41+
If you're on a Mac or Linux-based host machine, you can install and use the EMSDK directly to perform a build.
42+
Note that if you run into bugs with this configuration, we highly encourage you to use the containerized development environment instead, as detailed above.
43+
44+
Instructions:
45+
46+
1. [Install the EMSDK](https://emscripten.org/docs/getting_started/downloads.html)
47+
2. Clone this repository
48+
3. Run `$ npm install` to install the required modules
49+
4. Run `$ npm test` to ensure all tests pass
50+
5. Run `$ npm rebuild` to re-compile the project from scratch (using the version of EMSDK installed in the container).
51+
6. Run `$ npm test` to ensure all tests pass after said rebuild
52+
53+
## Compiling SQLite with different options
54+
55+
In order to enable extensions like FTS5, change the CFLAGS in the [Makefile](Makefile) and run `npm run rebuild`:
56+
57+
``` diff
58+
CFLAGS = \
59+
-O2 \
60+
-DSQLITE_OMIT_LOAD_EXTENSION \
61+
-DSQLITE_DISABLE_LFS \
62+
-DSQLITE_ENABLE_FTS3 \
63+
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
64+
+ -DSQLITE_ENABLE_FTS5 \
65+
-DSQLITE_THREADSAFE=0
66+
```

0 commit comments

Comments
 (0)