-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathindex.js
36 lines (25 loc) · 978 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { column, Schema, Table, PowerSyncDatabase, createBaseLogger } from '@powersync/web';
createBaseLogger().useDefaults();
const customers = new Table({ name: column.text });
export const AppSchema = new Schema({ customers });
let PowerSync;
const openDatabase = async (encryptionKey) => {
PowerSync = new PowerSyncDatabase({
schema: AppSchema,
database: { dbFilename: 'example-encryption.db' },
encryptionKey: encryptionKey
});
await PowerSync.init();
// Run local statements.
await PowerSync.execute('INSERT INTO customers(id, name) VALUES(uuid(), ?)', ['Fred']);
const result = await PowerSync.getAll('SELECT * FROM customers');
console.log('contents of customers: ', result);
console.table(result);
};
document.addEventListener('DOMContentLoaded', async (event) => {
let encryptionKey = '';
while (!encryptionKey) {
encryptionKey = prompt('Enter encryption key (non-empty string):');
}
openDatabase(encryptionKey);
});