Skip to content

Commit 73cf34a

Browse files
committed
Prettier write
1 parent d481926 commit 73cf34a

30 files changed

+594
-572
lines changed

.eslintrc.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ module.exports = {
44
node: true,
55
es2021: true,
66
jest: true,
7-
worker: true
7+
worker: true,
88
},
9-
extends: 'eslint:recommended',
9+
extends: "eslint:recommended",
1010
parserOptions: {
1111
ecmaVersion: 12,
12-
sourceType: 'module'
12+
sourceType: "module",
1313
},
1414
rules: {
15-
'no-unused-vars': 'off',
16-
'no-inner-declarations': 'off'
17-
}
15+
"no-unused-vars": "off",
16+
"no-inner-declarations": "off",
17+
},
1818
};

.github/workflows/node.js.yml

+12-13
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@ on: [push, pull_request]
77

88
jobs:
99
build:
10-
1110
runs-on: ubuntu-latest
1211

1312
steps:
14-
- uses: actions/checkout@v2
15-
- name: Use Node.js ${{ matrix.node-version }}
16-
uses: actions/setup-node@v2
17-
with:
18-
node-version: 15.x
19-
- uses: actions/cache@v2
20-
with:
21-
path: '**/node_modules'
22-
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
23-
- run: yarn
24-
- run: yarn prettier-check
25-
- run: yarn lint-check --max-warnings 0
13+
- uses: actions/checkout@v2
14+
- name: Use Node.js ${{ matrix.node-version }}
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: 15.x
18+
- uses: actions/cache@v2
19+
with:
20+
path: "**/node_modules"
21+
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
22+
- run: yarn
23+
- run: yarn prettier-check
24+
- run: yarn lint-check --max-warnings 0

README.md

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
This is an absurd project.
32

43
It implements a backend for [sql.js](https://github.com/sql-js/sql.js/) (sqlite3 compiled for the web) that treats IndexedDB like a disk and stores data in blocks there. That means your sqlite3 database is persisted. And not in the terrible way of reading and writing the whole image at once -- it reads and writes your db in small chunks.
@@ -26,10 +25,10 @@ Right now you need to use my fork of `sql.js`, but I'm going to open a PR and ho
2625
absurd-sql **must** run in a worker. This is fine because you really shouldn't be blocking the main thread anyway. So on the main thread, do this:
2726

2827
```js
29-
import { initBackend } from 'absurd-sql/dist/indexeddb-main-thread';
28+
import { initBackend } from "absurd-sql/dist/indexeddb-main-thread";
3029

3130
function init() {
32-
let worker = new Worker(new URL('./index.worker.js', import.meta.url));
31+
let worker = new Worker(new URL("./index.worker.js", import.meta.url));
3332
// This is only required because Safari doesn't support nested
3433
// workers. This installs a handler that will proxy creating web
3534
// workers through the main thread
@@ -42,21 +41,21 @@ init();
4241
Then in `index.worker.js` do this:
4342
4443
```js
45-
import initSqlJs from '@jlongster/sql.js';
46-
import { SQLiteFS } from 'absurd-sql';
47-
import IndexedDBBackend from 'absurd-sql/dist/indexeddb-backend';
44+
import initSqlJs from "@jlongster/sql.js";
45+
import { SQLiteFS } from "absurd-sql";
46+
import IndexedDBBackend from "absurd-sql/dist/indexeddb-backend";
4847

4948
async function run() {
50-
let SQL = await initSqlJs({ locateFile: file => file });
49+
let SQL = await initSqlJs({ locateFile: (file) => file });
5150
let sqlFS = new SQLiteFS(SQL.FS, new IndexedDBBackend());
5251
SQL.register_for_idb(sqlFS);
5352

54-
SQL.FS.mkdir('/sql');
55-
SQL.FS.mount(sqlFS, {}, '/sql');
53+
SQL.FS.mkdir("/sql");
54+
SQL.FS.mount(sqlFS, {}, "/sql");
5655

57-
const path = '/sql/db.sqlite';
58-
if (typeof SharedArrayBuffer === 'undefined') {
59-
let stream = SQL.FS.open(path, 'a+');
56+
const path = "/sql/db.sqlite";
57+
if (typeof SharedArrayBuffer === "undefined") {
58+
let stream = SQL.FS.open(path, "a+");
6059
await stream.node.contents.readIfFallback();
6160
SQL.FS.close(stream);
6261
}
@@ -67,16 +66,16 @@ async function run() {
6766
PRAGMA journal_mode=MEMORY;
6867
`);
6968

70-
// Your code
69+
// Your code
7170
}
7271
```
7372
7473
## Requirements
7574
7675
Because this uses `SharedArrayBuffer` and the `Atomics` API, there are some requirement for code to run.
7776
78-
* It must be run in a worker thread (you shouldn't block the main thread with queries anyway)
79-
* Your server must respond with the following headers:
77+
- It must be run in a worker thread (you shouldn't block the main thread with queries anyway)
78+
- Your server must respond with the following headers:
8079
8180
```
8281
Cross-Origin-Opener-Policy: same-origin
@@ -113,7 +112,7 @@ Read [this blog post](https://jlongster.com/future-sql-web) for more details.
113112
114113
There are several things that could be done:
115114
116-
* Add a bunch more tests
117-
* Implement a `webkitFileSystem` backend
118-
* I already started it [here](https://gist.github.com/jlongster/ec00ddbb47b4b29897ab5939b8e32fbe), but initial results showed that it was way slower?
119-
* Bug fixes
115+
- Add a bunch more tests
116+
- Implement a `webkitFileSystem` backend
117+
- I already started it [here](https://gist.github.com/jlongster/ec00ddbb47b4b29897ab5939b8e32fbe), but initial results showed that it was way slower?
118+
- Bug fixes

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = { plugins: ['@babel/plugin-transform-modules-commonjs'] };
1+
module.exports = { plugins: ["@babel/plugin-transform-modules-commonjs"] };

jest.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
22
transformIgnorePatterns: [
33
// Change MODULE_NAME_HERE to your module that isn't being compiled
4-
'/node_modules/(?!perf-deets).+\\.js$'
4+
"/node_modules/(?!perf-deets).+\\.js$",
55
],
66
moduleNameMapper: {
7-
'perf-deets': 'perf-deets/noop'
8-
}
7+
"perf-deets": "perf-deets/noop",
8+
},
99
};

rollup.config.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
import * as path from 'path';
2-
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
3-
import { nodeResolve } from '@rollup/plugin-node-resolve';
4-
import alias from '@rollup/plugin-alias';
5-
import { terser } from 'rollup-plugin-terser';
1+
import * as path from "path";
2+
import webWorkerLoader from "rollup-plugin-web-worker-loader";
3+
import { nodeResolve } from "@rollup/plugin-node-resolve";
4+
import alias from "@rollup/plugin-alias";
5+
import { terser } from "rollup-plugin-terser";
66

77
function getConfig(entry, filename, perf) {
88
// Remove the extension
9-
let basename = filename.replace(/\.[^.]*/, '');
9+
let basename = filename.replace(/\.[^.]*/, "");
1010

1111
return {
1212
input: entry,
1313
output: {
14-
dir: perf ? 'dist/perf' : 'dist',
14+
dir: perf ? "dist/perf" : "dist",
1515
entryFileNames: filename,
1616
chunkFileNames: `${basename}-[name]-[hash].js`,
17-
format: 'esm',
18-
exports: 'named'
17+
format: "esm",
18+
exports: "named",
1919
},
2020
plugins: [
2121
!perf &&
2222
alias({
2323
entries: {
24-
'perf-deets': path.resolve(
24+
"perf-deets": path.resolve(
2525
__dirname,
26-
'./node_modules/perf-deets/noop.js'
27-
)
28-
}
26+
"./node_modules/perf-deets/noop.js"
27+
),
28+
},
2929
}),
3030
webWorkerLoader({
3131
pattern: /.*\/worker\.js/,
32-
targetPlatform: 'browser',
32+
targetPlatform: "browser",
3333
external: [],
34-
plugins: [terser()]
34+
plugins: [terser()],
3535
}),
36-
nodeResolve()
36+
nodeResolve(),
3737
],
38-
...(perf ? { external: ['perf-deets'] } : {})
38+
...(perf ? { external: ["perf-deets"] } : {}),
3939
};
4040
}
4141

4242
export default [
43-
getConfig('src/index.js', 'index.js'),
44-
getConfig('src/memory/backend.js', 'memory-backend.js'),
45-
getConfig('src/indexeddb/backend.js', 'indexeddb-backend.js'),
46-
getConfig('src/indexeddb/main-thread.js', 'indexeddb-main-thread.js'),
47-
getConfig('src/indexeddb/backend.js', 'indexeddb-backend.js', true),
48-
getConfig('src/indexeddb/main-thread.js', 'indexeddb-main-thread.js', true)
43+
getConfig("src/index.js", "index.js"),
44+
getConfig("src/memory/backend.js", "memory-backend.js"),
45+
getConfig("src/indexeddb/backend.js", "indexeddb-backend.js"),
46+
getConfig("src/indexeddb/main-thread.js", "indexeddb-main-thread.js"),
47+
getConfig("src/indexeddb/backend.js", "indexeddb-backend.js", true),
48+
getConfig("src/indexeddb/main-thread.js", "indexeddb-main-thread.js", true),
4949
];

src/examples/bench/index.html

+51-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<!DOCTYPE html>
22
<body>
33
<style type="text/css">
4-
html, body, .container {
4+
html,
5+
body,
6+
.container {
57
height: 100%;
68
}
79

@@ -43,7 +45,7 @@
4345
display: block;
4446
margin-bottom: 5px;
4547
}
46-
48+
4749
.output > div {
4850
margin-bottom: 10px;
4951
}
@@ -81,19 +83,20 @@
8183

8284
<div class="container">
8385
<div class="text">
84-
This is sqlite3 running in your browser with a backend that
85-
properly persists the database in IndexedDB
86-
(<a href="https://github.com/jlongster/absurd-sql">absurd-sql</a>).
87-
It stores each page from the db as a separate item, treating IDB
88-
like a hard disk. It never has to load the full DB into memory
89-
and can update it with small individual writes.
86+
This is sqlite3 running in your browser with a backend that properly
87+
persists the database in IndexedDB (<a
88+
href="https://github.com/jlongster/absurd-sql"
89+
>absurd-sql</a
90+
>). It stores each page from the db as a separate item, treating IDB like
91+
a hard disk. It never has to load the full DB into memory and can update
92+
it with small individual writes.
9093
</div>
9194

9295
<div class="text last">
93-
The below examples are meant to be stress tests, showing that it
94-
can handle large amounts of data and queries that need to scan
95-
all of it. With more normal cases and a small cache, it works
96-
really well. It easily beats IndexedDB up to a factor of 10.
96+
The below examples are meant to be stress tests, showing that it can
97+
handle large amounts of data and queries that need to scan all of it. With
98+
more normal cases and a small cache, it works really well. It easily beats
99+
IndexedDB up to a factor of 10.
97100
</div>
98101

99102
<div>
@@ -110,31 +113,55 @@
110113
</div>
111114

112115
<div class="options">
113-
<label><input type="checkbox" name="profile"> Record performance profile</label>
114-
<label><input type="checkbox" name="raw-indexeddb"> Use raw IndexedDB</label>
116+
<label
117+
><input type="checkbox" name="profile" /> Record performance
118+
profile</label
119+
>
120+
<label
121+
><input type="checkbox" name="raw-indexeddb" /> Use raw IndexedDB</label
122+
>
115123
</div>
116124

117125
<div class="disable-if-raw-idb">
118126
<div class="options">
119127
Backend:
120-
<label><input type="radio" name="backend" value="idb" checked> IndexedDB</label>
121-
<label><input type="radio" name="backend" value="memory"> Memory</label>
128+
<label
129+
><input type="radio" name="backend" value="idb" checked />
130+
IndexedDB</label
131+
>
132+
<label
133+
><input type="radio" name="backend" value="memory" /> Memory</label
134+
>
122135
</div>
123136

124137
<div class="options">
125138
Cache size:
126-
<label><input type="radio" name="cacheSize" value="0" checked> 0MB</label>
127-
<label><input type="radio" name="cacheSize" value="2000"> 2MB</label>
128-
<label><input type="radio" name="cacheSize" value="10000"> 10MB</label>
129-
<label><input type="radio" name="cacheSize" value="60000"> 60MB</label>
130-
<span class="warning" style="font-size: 13px; color: #8080a0">Using a cache will greatly improve perf, but no cache shows the full number of read/writes</span>
139+
<label
140+
><input type="radio" name="cacheSize" value="0" checked /> 0MB</label
141+
>
142+
<label><input type="radio" name="cacheSize" value="2000" /> 2MB</label>
143+
<label
144+
><input type="radio" name="cacheSize" value="10000" /> 10MB</label
145+
>
146+
<label
147+
><input type="radio" name="cacheSize" value="60000" /> 60MB</label
148+
>
149+
<span class="warning" style="font-size: 13px; color: #8080a0"
150+
>Using a cache will greatly improve perf, but no cache shows the full
151+
number of read/writes</span
152+
>
131153
</div>
132154

133155
<div class="options pageSize">
134156
Page size:
135-
<label><input type="radio" name="pageSize" value="4096" checked> 4096</label>
136-
<label><input type="radio" name="pageSize" value="8192"> 8192</label>
137-
<label><input type="radio" name="pageSize" value="16384"> 16384</label>
157+
<label
158+
><input type="radio" name="pageSize" value="4096" checked />
159+
4096</label
160+
>
161+
<label><input type="radio" name="pageSize" value="8192" /> 8192</label>
162+
<label
163+
><input type="radio" name="pageSize" value="16384" /> 16384</label
164+
>
138165
</div>
139166
</div>
140167

0 commit comments

Comments
 (0)