Skip to content

Commit f60fbed

Browse files
DominicGBauerDominicGBauer
and
DominicGBauer
authored
chore: update readme and update to PowerSyncDatabase (#220)
Co-authored-by: DominicGBauer <[email protected]>
1 parent 86cfa71 commit f60fbed

File tree

7 files changed

+37
-37
lines changed

7 files changed

+37
-37
lines changed

packages/kysely-driver/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ Table column object type definitions are not yet available in JavaScript.
1414

1515
```js
1616
import { wrapPowerSyncWithKysely } from '@powersync/kysely-driver';
17-
import { WASQLitePowerSyncDatabaseOpenFactory } from '@powersync/web';
17+
import { PowerSyncDatabase } from '@powersync/web';
1818
import { appSchema } from './schema';
1919

20-
const factory = new WASQLitePowerSyncDatabaseOpenFactory({
20+
export const powerSyncDb = new PowerSyncDatabase({
21+
database: {
22+
dbFilename: 'test.sqlite'
23+
},
2124
schema: appSchema,
22-
dbFilename: 'test.sqlite'
2325
});
2426

25-
export const powerSyncDb = factory.getInstance();
26-
2727
export const db = wrapPowerSyncWithKysely(powerSyncDb);
2828
```
2929

@@ -32,7 +32,7 @@ See an [example](https://github.com/powersync-ja/powersync-js/blob/main/demos/re
3232

3333
```TypeScript
3434
import { wrapPowerSyncWithKysely } from '@powersync/kysely-driver';
35-
import { WASQLitePowerSyncDatabaseOpenFactory } from "@powersync/web";
35+
import { PowerSyncDatabase } from "@powersync/web";
3636

3737
// Define schema as in: https://docs.powersync.com/usage/installation/client-side-setup/define-your-schema
3838
import { appSchema } from "./schema";
@@ -46,13 +46,13 @@ export type Database = {
4646
lists: ListsRecord; // Interface defined externally for list item object
4747
};
4848

49-
const factory = new WASQLitePowerSyncDatabaseOpenFactory({
49+
export const powerSyncDb = new PowerSyncDatabase({
50+
database: {
51+
dbFilename: "test.sqlite"
52+
},
5053
schema: appSchema,
51-
dbFilename: "test.sqlite",
5254
});
5355

54-
export const powerSyncDb = factory.getInstance();
55-
5656
// `db` now automatically contains types for defined tables
5757
export const db = wrapPowerSyncWithKysely<Database>(powerSyncDb)
5858
```
+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Schema, TableV2, WASQLitePowerSyncDatabaseOpenFactory, column } from '@powersync/web';
1+
import { Schema, TableV2, PowerSyncDatabase, column } from '@powersync/web';
22
import { wrapPowerSyncWithKysely } from '../../src/sqlite/db';
33
import { Database } from './types';
44

@@ -9,12 +9,14 @@ const users = new TableV2({
99
export const TestSchema = new Schema({ users });
1010

1111
export const getPowerSyncDb = () => {
12-
const factory = new WASQLitePowerSyncDatabaseOpenFactory({
13-
dbFilename: 'test.db',
12+
const database = new PowerSyncDatabase({
13+
database: {
14+
dbFilename: 'test.db'
15+
},
1416
schema: TestSchema
1517
});
1618

17-
return factory.getInstance();
19+
return database;
1820
};
1921

2022
export const getKyselyDb = wrapPowerSyncWithKysely<Database>(getPowerSyncDb());

packages/react/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Configure a PowerSync DB connection and add it to a context provider.
66

77
```JSX
88
// App.jsx
9-
import { PowerSyncDatabase } from '@powersync/react-native';
9+
import { PowerSyncDatabase } from '@powersync/web';
10+
// or for React Native
11+
// import { PowerSyncDatabase } from '@powersync/react-native';
1012
import { PowerSyncContext } from "@powersync/react";
1113
export const App = () => {
1214
const powerSync = React.useMemo(() => {

packages/web/tests/crud.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
22
import { AbstractPowerSyncDatabase, Column, ColumnType, CrudEntry, Schema, Table, UpdateType } from '@powersync/common';
3-
import { WASQLitePowerSyncDatabaseOpenFactory } from '@powersync/web';
3+
import { PowerSyncDatabase } from '@powersync/web';
44
import { v4 as uuid } from 'uuid';
55
import { generateTestDb } from './utils/testDb';
66

@@ -165,13 +165,15 @@ describe('CRUD Tests', () => {
165165
it('INSERT-only tables', async () => {
166166
await powersync.disconnectAndClear();
167167

168-
powersync = new WASQLitePowerSyncDatabaseOpenFactory({
168+
powersync = new PowerSyncDatabase({
169169
/**
170170
* Deleting the IndexDB seems to freeze the test.
171171
* Use a new DB for each run to keep CRUD counters
172172
* consistent
173173
*/
174-
dbFilename: 'test.db' + uuid(),
174+
database: {
175+
dbFilename: 'test.db' + uuid()
176+
},
175177
schema: new Schema([
176178
new Table({
177179
name: 'logs',
@@ -185,7 +187,7 @@ describe('CRUD Tests', () => {
185187
flags: {
186188
enableMultiTabs: false
187189
}
188-
}).getInstance();
190+
});
189191

190192
expect(await powersync.getAll('SELECT * FROM ps_crud')).empty;
191193

tools/diagnostics-app/src/library/powersync/ConnectionManager.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
BaseListener,
33
BaseObserver,
4-
WASQLitePowerSyncDatabaseOpenFactory,
4+
PowerSyncDatabase,
55
WebRemote,
66
WebStreamingSyncImplementation,
77
WebStreamingSyncImplementationOptions
@@ -16,10 +16,12 @@ Logger.setLevel(Logger.DEBUG);
1616

1717
export const schemaManager = new DynamicSchemaManager();
1818

19-
export const db = new WASQLitePowerSyncDatabaseOpenFactory({
20-
dbFilename: 'example.db',
19+
export const db = new PowerSyncDatabase({
20+
database: {
21+
dbFilename: 'example.db'
22+
},
2123
schema: schemaManager.buildSchema()
22-
}).getInstance();
24+
});
2325
export const connector = new TokenConnector();
2426

2527
const remote = new WebRemote(connector);

tools/diagnostics-app/src/library/powersync/DynamicSchemaManager.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
Column,
3-
ColumnType,
4-
DBAdapter,
5-
OpTypeEnum,
6-
Schema,
7-
SyncDataBatch,
8-
Table
9-
} from '@powersync/web';
1+
import { Column, ColumnType, DBAdapter, OpTypeEnum, Schema, SyncDataBatch, Table } from '@powersync/web';
102
import { AppSchema } from './AppSchema';
113
import { JsSchemaGenerator } from './JsSchemaGenerator';
124

@@ -30,14 +22,14 @@ export class DynamicSchemaManager {
3022

3123
async updateFromOperations(batch: SyncDataBatch) {
3224
let schemaDirty = false;
33-
for (let bucket of batch.buckets) {
25+
for (const bucket of batch.buckets) {
3426
// Build schema
35-
for (let op of bucket.data) {
27+
for (const op of bucket.data) {
3628
if (op.op.value == OpTypeEnum.PUT && op.data != null) {
3729
this.tables[op.object_type!] ??= {};
3830
const table = this.tables[op.object_type!];
3931
const data = JSON.parse(op.data);
40-
for (let [key, value] of Object.entries(data)) {
32+
for (const [key, value] of Object.entries(data)) {
4133
if (key == 'id') {
4234
continue;
4335
}

tools/diagnostics-app/src/library/powersync/RecordingStorageAdapter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class RecordingStorageAdapter extends SqliteBucketStorage {
2424
async setTargetCheckpoint(checkpoint: Checkpoint) {
2525
await super.setTargetCheckpoint(checkpoint);
2626
await this.rdb.writeTransaction(async (tx) => {
27-
for (let bucket of checkpoint.buckets) {
27+
for (const bucket of checkpoint.buckets) {
2828
await tx.execute(
2929
`INSERT OR REPLACE INTO local_bucket_data(id, total_operations, last_op, download_size, downloading)
3030
VALUES (
@@ -53,7 +53,7 @@ export class RecordingStorageAdapter extends SqliteBucketStorage {
5353
await super.saveSyncData(batch);
5454

5555
await this.rdb.writeTransaction(async (tx) => {
56-
for (let bucket of batch.buckets) {
56+
for (const bucket of batch.buckets) {
5757
// Record metrics
5858
const size = JSON.stringify(bucket.data).length;
5959
await tx.execute(

0 commit comments

Comments
 (0)