mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-04 17:04:18 +01:00
add comments and small test adjustments
This commit is contained in:
@@ -268,7 +268,7 @@ let workerRequestId = 0;
|
||||
function waitForWorkerResponse(worker: Worker, id: number): Promise<any> {
|
||||
let waitResolve, waitReject;
|
||||
const callback = msg => {
|
||||
if (msg.data.id == id) {
|
||||
if (msg.data.__turso__ && msg.data.id == id) {
|
||||
if (msg.data.error != null) {
|
||||
waitReject(msg.data.error)
|
||||
} else {
|
||||
@@ -376,31 +376,31 @@ function setupWebWorker() {
|
||||
if (e.data.__turso__ == 'register') {
|
||||
try {
|
||||
await opfs.registerFile(e.data.path);
|
||||
self.postMessage({ id: e.data.id });
|
||||
self.postMessage({ __turso__: true, id: e.data.id });
|
||||
} catch (error) {
|
||||
self.postMessage({ id: e.data.id, error: error });
|
||||
self.postMessage({ __turso__: true, id: e.data.id, error: error });
|
||||
}
|
||||
return;
|
||||
} else if (e.data.__turso__ == 'unregister') {
|
||||
try {
|
||||
await opfs.unregisterFile(e.data.path);
|
||||
self.postMessage({ id: e.data.id });
|
||||
self.postMessage({ __turso__: true, id: e.data.id });
|
||||
} catch (error) {
|
||||
self.postMessage({ id: e.data.id, error: error });
|
||||
self.postMessage({ __turso__: true, id: e.data.id, error: error });
|
||||
}
|
||||
return;
|
||||
} else if (e.data.__turso__ == 'read_async') {
|
||||
let result = opfs.read(e.data.handle, getUint8ArrayFromMemory(memory, e.data.ptr, e.data.len), e.data.offset);
|
||||
self.postMessage({ id: e.data.id, result: result });
|
||||
self.postMessage({ __turso__: true, id: e.data.id, result: result });
|
||||
} else if (e.data.__turso__ == 'write_async') {
|
||||
let result = opfs.write(e.data.handle, getUint8ArrayFromMemory(memory, e.data.ptr, e.data.len), e.data.offset);
|
||||
self.postMessage({ id: e.data.id, result: result });
|
||||
self.postMessage({ __turso__: true, id: e.data.id, result: result });
|
||||
} else if (e.data.__turso__ == 'sync_async') {
|
||||
let result = opfs.sync(e.data.handle);
|
||||
self.postMessage({ id: e.data.id, result: result });
|
||||
self.postMessage({ __turso__: true, id: e.data.id, result: result });
|
||||
} else if (e.data.__turso__ == 'truncate_async') {
|
||||
let result = opfs.truncate(e.data.handle, e.data.len);
|
||||
self.postMessage({ id: e.data.id, result: result });
|
||||
self.postMessage({ __turso__: true, id: e.data.id, result: result });
|
||||
}
|
||||
handler.handle(e)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ class Database extends DatabasePromise {
|
||||
constructor(path: string, opts: DatabaseOpts = {}) {
|
||||
super(new NativeDatabase(path, opts) as unknown as any)
|
||||
}
|
||||
/**
|
||||
* connect database and pre-open necessary files in the OPFS
|
||||
*/
|
||||
override async connect() {
|
||||
if (!this.memory) {
|
||||
const worker = await init();
|
||||
@@ -26,6 +29,9 @@ class Database extends DatabasePromise {
|
||||
}
|
||||
await super.connect();
|
||||
}
|
||||
/**
|
||||
* close the database and relevant files
|
||||
*/
|
||||
async close() {
|
||||
if (this.name != null && this.#worker != null) {
|
||||
await Promise.all([
|
||||
|
||||
@@ -15,6 +15,9 @@ class Database extends DatabasePromise {
|
||||
constructor(path: string, opts: DatabaseOpts = {}) {
|
||||
super(new NativeDatabase(path, opts) as unknown as any)
|
||||
}
|
||||
/**
|
||||
* connect database and pre-open necessary files in the OPFS
|
||||
*/
|
||||
override async connect() {
|
||||
if (!this.memory) {
|
||||
const worker = await init();
|
||||
@@ -26,6 +29,9 @@ class Database extends DatabasePromise {
|
||||
}
|
||||
await super.connect();
|
||||
}
|
||||
/**
|
||||
* close the database and relevant files
|
||||
*/
|
||||
async close() {
|
||||
if (this.name != null && this.#worker != null) {
|
||||
await Promise.all([
|
||||
|
||||
@@ -15,6 +15,9 @@ class Database extends DatabasePromise {
|
||||
constructor(path: string, opts: DatabaseOpts = {}) {
|
||||
super(new NativeDatabase(path, opts) as unknown as any)
|
||||
}
|
||||
/**
|
||||
* connect database and pre-open necessary files in the OPFS
|
||||
*/
|
||||
override async connect() {
|
||||
if (!this.memory) {
|
||||
const worker = await init();
|
||||
@@ -26,6 +29,9 @@ class Database extends DatabasePromise {
|
||||
}
|
||||
await super.connect();
|
||||
}
|
||||
/**
|
||||
* close the database and relevant files
|
||||
*/
|
||||
async close() {
|
||||
if (this.name != null && this.#worker != null) {
|
||||
await Promise.all([
|
||||
|
||||
@@ -15,6 +15,9 @@ class Database extends DatabasePromise {
|
||||
constructor(path: string, opts: DatabaseOpts = {}) {
|
||||
super(new NativeDatabase(path, opts) as unknown as any)
|
||||
}
|
||||
/**
|
||||
* connect database and pre-open necessary files in the OPFS
|
||||
*/
|
||||
override async connect() {
|
||||
if (!this.memory) {
|
||||
const worker = await init();
|
||||
@@ -26,6 +29,9 @@ class Database extends DatabasePromise {
|
||||
}
|
||||
await super.connect();
|
||||
}
|
||||
/**
|
||||
* close the database and relevant files
|
||||
*/
|
||||
async close() {
|
||||
if (this.name != null && this.#worker != null) {
|
||||
await Promise.all([
|
||||
|
||||
@@ -14,7 +14,7 @@ test('explicit connect', async () => {
|
||||
const db = new Database(':memory:');
|
||||
expect(() => db.prepare("SELECT 1")).toThrowError(/database must be connected/g);
|
||||
await db.connect();
|
||||
db.prepare("SELECT 1");
|
||||
expect(await db.prepare("SELECT 1 as x").all()).toEqual([{ x: 1 }]);
|
||||
})
|
||||
|
||||
test('on-disk db large inserts', async () => {
|
||||
|
||||
@@ -52,6 +52,9 @@ class Database {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* connect database
|
||||
*/
|
||||
async connect() {
|
||||
await this.db.connectAsync();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ test('explicit connect', async () => {
|
||||
const db = new Database(':memory:');
|
||||
expect(() => db.prepare("SELECT 1")).toThrowError(/database must be connected/g);
|
||||
await db.connect();
|
||||
db.prepare("SELECT 1");
|
||||
expect(await db.prepare("SELECT 1 as x").all()).toEqual([{ x: 1 }]);
|
||||
})
|
||||
|
||||
test('on-disk db', async () => {
|
||||
|
||||
Reference in New Issue
Block a user