Skip to content

Commit c3081a4

Browse files
committed
Test watching queries and uploads
1 parent afd62ab commit c3081a4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

demos/example-node/src/main.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,36 @@ const main = async () => {
2424
});
2525

2626
await db.connect(new DemoConnector());
27-
2827
await db.waitForFirstSync();
29-
console.log(await db.getAll('SELECT * FROM lists;'));
28+
29+
let hasFirstRow: ((value: any) => void) | null = null;
30+
const firstRow = new Promise((resolve) => hasFirstRow = resolve);
31+
const watchLists = async () => {
32+
for await (const rows of db.watch('SELECT * FROM lists')) {
33+
if (hasFirstRow) {
34+
hasFirstRow(null);
35+
hasFirstRow = null;
36+
}
37+
console.log('Has todo items', rows.rows?._array);
38+
}
39+
};
40+
41+
watchLists();
42+
await firstRow;
43+
44+
// await db.execute("INSERT INTO lists (id, created_at, name, owner_id) VALUEs (uuid(), 'test', 'test', 'test');");
3045
};
3146

3247
class DemoConnector implements PowerSyncBackendConnector {
3348
async fetchCredentials() {
3449
return {
35-
endpoint: '', // todo
36-
token: '' // todo
50+
endpoint: 'https://678775966cf706da85f4e447.powersync.journeyapps.com', // todo
51+
token: 'eyJhbGciOiJSUzI1NiIsImtpZCI6InBvd2Vyc3luYy1kZXYtMzIyM2Q0ZTMifQ.eyJzdWIiOiI5MGQ5MzBhZi1iYmVkLTQ0NDgtOWM0NS1kYWQyZGYzMDAwNWYiLCJpYXQiOjE3NDEwMTU4NjUsImlzcyI6Imh0dHBzOi8vcG93ZXJzeW5jLWFwaS5qb3VybmV5YXBwcy5jb20iLCJhdWQiOiJodHRwczovLzY3ODc3NTk2NmNmNzA2ZGE4NWY0ZTQ0Ny5wb3dlcnN5bmMuam91cm5leWFwcHMuY29tIiwiZXhwIjoxNzQxMDU5MDY1fQ.aQqLOulvaOMKFtOUfbYuywLRjxmhs1J9hpdlkoSjw2m1_OTmnoVJkMRFKvO45k2I_ZD1GLg2sb6HoV2KNQHJPp2yMeL5eBENXt1HEy-WKU5ObrbwoQT0knkHnwZRmbGNwPYz3R21GibKDdD8chILVtNkSXoy3LjAUmywdzzhMBmmJwiIxP5Ew_K4XAxBU2pDyjX3FNvISHdB60IPgGBQUz3Ke_t-4ZD-k-EUHVLDufhxsDRSwhIKG26PPUqJdZ4YPlqwtjjZrVHy_B4XQBtRsAjqhf61ZLFEx6xeHcze-xZRNVsTw3qTmAFC4Vf9Ezka5jhMppM_HAtPn_wyzWUauA' // todo
3752
};
3853
}
3954

4055
async uploadData(database: AbstractPowerSyncDatabase) {
56+
await new Promise((resolve) => setTimeout(resolve, 10_000));
4157
throw 'not implemented: DemoConnector.uploadData';
4258
}
4359
}

packages/node/src/db/PowerSyncDatabase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
5353
await this.waitForReady();
5454
await connector.uploadData(this);
5555
},
56-
retryDelayMs: this.options.retryDelay,
56+
retryDelayMs: this.options.retryDelayMs,
5757
crudUploadThrottleMs: this.options.crudUploadThrottleMs,
5858
identifier: this.database.name
5959
});

0 commit comments

Comments
 (0)