Skip to content

Commit

Permalink
More cleanup; BlockedFS -> SQLiteFS
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Aug 8, 2021
1 parent 31d076b commit d768660
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The following code will get you up and running:

```js
import initSqlJS from '@jlongster/sql.js';
import { BlockedFS } from 'absurd-sql.js-backend';
import { SqliteFS } from 'absurd-sql.js-backend';
import IndexedDBBackend from 'absurd-sql.js-backend/dist/indexeddb-backend');

async function run() {
Expand All @@ -46,7 +46,7 @@ async function run() {

// Create the backend and filesystem
let backend = new IndexedDBBackend(4096);
let BFS = new BlockedFS(SQL.FS, backend);
let BFS = new SqliteFS(SQL.FS, backend);

// For now, we need to initialize some internal state. This
// API will be improved
Expand Down
2 changes: 0 additions & 2 deletions src/examples/fts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ function init() {
});

worker.postMessage({ type: 'ui-invoke', name: 'count' });

supportNestedWorkers(worker);
}

let methods = ['load'];
Expand Down
21 changes: 5 additions & 16 deletions src/examples/fts/main.worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import initSqlJs from '@jlongster/sql.js';
import { BlockedFS } from '../..';
import { SQLiteFS } from '../..';
import * as uuid from 'uuid';
import MemoryBackend from '../../memory/backend';
import IndexedDBBackend from '../../indexeddb/backend';
Expand All @@ -12,30 +12,19 @@ let pageSize = 4096;
let dbName = `fts.sqlite`;

let idbBackend = new IndexedDBBackend(4096 * 2);
let BFS;
let sqlFS;

// Helper methods

let SQL = null;
let ready = null;
async function _init() {
SQL = await initSqlJs({ locateFile: file => file });
BFS = new BlockedFS(SQL.FS, idbBackend);
SQL.register_for_idb(BFS);

try {
await BFS.init();
} catch (e) {
if (e.message.includes('SharedArrayBuffer')) {
output(
'<code>SharedArrayBuffer</code> is not available in your browser. It is required, but in the future we will provide a fallback.'
);
}
throw e;
}
sqlFS = new SQLiteFS(SQL.FS, idbBackend);
SQL.register_for_idb(sqlFS);

SQL.FS.mkdir('/blocked');
SQL.FS.mount(BFS, {}, '/blocked');
SQL.FS.mount(sqlFS, {}, '/blocked');
}

function init() {
Expand Down
26 changes: 13 additions & 13 deletions src/examples/large-data/main.worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import initSqlJs from '@jlongster/sql.js/dist/sql-wasm-debug.js';
import { BlockedFS } from '../..';
import { SQLiteFS } from '../..';
import * as uuid from 'uuid';
import MemoryBackend from '../../memory/backend';
import IndexedDBBackend from '../../indexeddb/backend';
Expand All @@ -15,16 +15,16 @@ let recordProfile = false;

let memoryBackend = new MemoryBackend({});
let idbBackend = new IndexedDBBackend();
let BFS;
let sqlFS;

// Helper methods

let SQL = null;
async function init() {
if (SQL == null) {
SQL = await initSqlJs({ locateFile: file => file });
BFS = new BlockedFS(SQL.FS, idbBackend);
SQL.register_for_idb(BFS);
sqlFS = new SQLiteFS(SQL.FS, idbBackend);
SQL.register_for_idb(sqlFS);

if (typeof SharedArrayBuffer === 'undefined') {
output(
Expand All @@ -33,7 +33,7 @@ async function init() {
}

SQL.FS.mkdir('/blocked');
SQL.FS.mount(BFS, {}, '/blocked');
SQL.FS.mount(sqlFS, {}, '/blocked');
}
}

Expand Down Expand Up @@ -108,13 +108,13 @@ async function populate() {
let db = await getDatabase();

if (recordProfile) {
BFS.backend.startProfile();
sqlFS.backend.startProfile();
}

queries.populate(db, output, uuid, count);

if (recordProfile) {
BFS.backend.stopProfile();
sqlFS.backend.stopProfile();
}

let { node } = SQL.FS.lookupPath(`/blocked/${dbName}`);
Expand All @@ -132,26 +132,26 @@ async function populate() {
async function countAll() {
let db = await getDatabase();
if (recordProfile) {
BFS.backend.startProfile();
sqlFS.backend.startProfile();
}

queries.countAll(db, output);

if (recordProfile) {
BFS.backend.stopProfile();
sqlFS.backend.stopProfile();
}
}

async function randomReads() {
let db = await getDatabase();
if (recordProfile) {
BFS.backend.startProfile();
sqlFS.backend.startProfile();
}

queries.randomReads(db, output);

if (recordProfile) {
BFS.backend.stopProfile();
sqlFS.backend.stopProfile();
}
}

Expand Down Expand Up @@ -220,9 +220,9 @@ if (typeof self !== 'undefined') {
// We dont really support swapping the backend like this,
// but it works for the demo
if (currentBackendType === 'memory') {
BFS.backend = memoryBackend;
sqlFS.backend = memoryBackend;
} else {
BFS.backend = idbBackend;
sqlFS.backend = idbBackend;
}
break;

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _BlockedFS from './blocked-fs';
import _SQLiteFS from './sqlite-fs';

// Right now we don't support `export from` so we do this manually
export const BlockedFS = _BlockedFS;
export const SQLiteFS = _SQLiteFS;
2 changes: 1 addition & 1 deletion src/indexeddb/backend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from '../blocked-file';
import { File } from '../sqlite-file';
import * as perf from 'perf-deets';
import { LOCK_TYPES, getPageSize, isSafeToWrite } from '../sqlite-util';
import { FileOps } from './file-ops';
Expand Down
2 changes: 1 addition & 1 deletion src/memory/backend.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File } from '../blocked-file';
import { File } from '../sqlite-file';

class FileOps {
constructor(filename, meta = null, data) {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/blocked-fs.js → src/sqlite-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const ERRNO_CODES = {
// This implements an emscripten-compatible filesystem that is means
// to be mounted to the one from `sql.js`. Example:
//
// let BFS = new BlockedFS(SQL.FS, idbBackend);
// let BFS = new SQLiteFS(SQL.FS, idbBackend);
// SQL.FS.mount(BFS, {}, '/blocked');
//
// Now any files created under '/blocked' will be handled by this
// filesystem, which creates a special file that handles read/writes
// in the way that we want.
export default class BlockedFS {
export default class SQLiteFS {
constructor(FS, backend) {
this.FS = FS;
this.backend = backend;
Expand Down

0 comments on commit d768660

Please sign in to comment.