diff --git a/packages/kysely-driver/README.md b/packages/kysely-driver/README.md index f0b738e1..846eb69d 100644 --- a/packages/kysely-driver/README.md +++ b/packages/kysely-driver/README.md @@ -14,16 +14,16 @@ Table column object type definitions are not yet available in JavaScript. ```js import { wrapPowerSyncWithKysely } from '@powersync/kysely-driver'; -import { WASQLitePowerSyncDatabaseOpenFactory } from '@powersync/web'; +import { PowerSyncDatabase } from '@powersync/web'; import { appSchema } from './schema'; -const factory = new WASQLitePowerSyncDatabaseOpenFactory({ +export const powerSyncDb = new PowerSyncDatabase({ + database: { + dbFilename: 'test.sqlite' + }, schema: appSchema, - dbFilename: 'test.sqlite' }); -export const powerSyncDb = factory.getInstance(); - export const db = wrapPowerSyncWithKysely(powerSyncDb); ``` @@ -32,7 +32,7 @@ See an [example](https://github.com/powersync-ja/powersync-js/blob/main/demos/re ```TypeScript import { wrapPowerSyncWithKysely } from '@powersync/kysely-driver'; -import { WASQLitePowerSyncDatabaseOpenFactory } from "@powersync/web"; +import { PowerSyncDatabase } from "@powersync/web"; // Define schema as in: https://docs.powersync.com/usage/installation/client-side-setup/define-your-schema import { appSchema } from "./schema"; @@ -46,13 +46,13 @@ export type Database = { lists: ListsRecord; // Interface defined externally for list item object }; -const factory = new WASQLitePowerSyncDatabaseOpenFactory({ +export const powerSyncDb = new PowerSyncDatabase({ + database: { + dbFilename: "test.sqlite" + }, schema: appSchema, - dbFilename: "test.sqlite", }); -export const powerSyncDb = factory.getInstance(); - // `db` now automatically contains types for defined tables export const db = wrapPowerSyncWithKysely(powerSyncDb) ``` diff --git a/packages/kysely-driver/tests/setup/db.ts b/packages/kysely-driver/tests/setup/db.ts index 2fe2390c..1d18c54c 100644 --- a/packages/kysely-driver/tests/setup/db.ts +++ b/packages/kysely-driver/tests/setup/db.ts @@ -1,4 +1,4 @@ -import { Schema, TableV2, WASQLitePowerSyncDatabaseOpenFactory, column } from '@powersync/web'; +import { Schema, TableV2, PowerSyncDatabase, column } from '@powersync/web'; import { wrapPowerSyncWithKysely } from '../../src/sqlite/db'; import { Database } from './types'; @@ -9,12 +9,14 @@ const users = new TableV2({ export const TestSchema = new Schema({ users }); export const getPowerSyncDb = () => { - const factory = new WASQLitePowerSyncDatabaseOpenFactory({ - dbFilename: 'test.db', + const database = new PowerSyncDatabase({ + database: { + dbFilename: 'test.db' + }, schema: TestSchema }); - return factory.getInstance(); + return database; }; export const getKyselyDb = wrapPowerSyncWithKysely(getPowerSyncDb()); diff --git a/packages/react/README.md b/packages/react/README.md index 0519057d..7ebc31c6 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -6,7 +6,9 @@ Configure a PowerSync DB connection and add it to a context provider. ```JSX // App.jsx -import { PowerSyncDatabase } from '@powersync/react-native'; +import { PowerSyncDatabase } from '@powersync/web'; +// or for React Native +// import { PowerSyncDatabase } from '@powersync/react-native'; import { PowerSyncContext } from "@powersync/react"; export const App = () => { const powerSync = React.useMemo(() => { diff --git a/packages/web/tests/crud.test.ts b/packages/web/tests/crud.test.ts index 07c2291f..c615d11b 100644 --- a/packages/web/tests/crud.test.ts +++ b/packages/web/tests/crud.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'; import { AbstractPowerSyncDatabase, Column, ColumnType, CrudEntry, Schema, Table, UpdateType } from '@powersync/common'; -import { WASQLitePowerSyncDatabaseOpenFactory } from '@powersync/web'; +import { PowerSyncDatabase } from '@powersync/web'; import { v4 as uuid } from 'uuid'; import { generateTestDb } from './utils/testDb'; @@ -165,13 +165,15 @@ describe('CRUD Tests', () => { it('INSERT-only tables', async () => { await powersync.disconnectAndClear(); - powersync = new WASQLitePowerSyncDatabaseOpenFactory({ + powersync = new PowerSyncDatabase({ /** * Deleting the IndexDB seems to freeze the test. * Use a new DB for each run to keep CRUD counters * consistent */ - dbFilename: 'test.db' + uuid(), + database: { + dbFilename: 'test.db' + uuid() + }, schema: new Schema([ new Table({ name: 'logs', @@ -185,7 +187,7 @@ describe('CRUD Tests', () => { flags: { enableMultiTabs: false } - }).getInstance(); + }); expect(await powersync.getAll('SELECT * FROM ps_crud')).empty; diff --git a/tools/diagnostics-app/src/library/powersync/ConnectionManager.ts b/tools/diagnostics-app/src/library/powersync/ConnectionManager.ts index 0f589cd1..ac838f2c 100644 --- a/tools/diagnostics-app/src/library/powersync/ConnectionManager.ts +++ b/tools/diagnostics-app/src/library/powersync/ConnectionManager.ts @@ -1,7 +1,7 @@ import { BaseListener, BaseObserver, - WASQLitePowerSyncDatabaseOpenFactory, + PowerSyncDatabase, WebRemote, WebStreamingSyncImplementation, WebStreamingSyncImplementationOptions @@ -16,10 +16,12 @@ Logger.setLevel(Logger.DEBUG); export const schemaManager = new DynamicSchemaManager(); -export const db = new WASQLitePowerSyncDatabaseOpenFactory({ - dbFilename: 'example.db', +export const db = new PowerSyncDatabase({ + database: { + dbFilename: 'example.db' + }, schema: schemaManager.buildSchema() -}).getInstance(); +}); export const connector = new TokenConnector(); const remote = new WebRemote(connector); diff --git a/tools/diagnostics-app/src/library/powersync/DynamicSchemaManager.ts b/tools/diagnostics-app/src/library/powersync/DynamicSchemaManager.ts index 737b8e1f..492548fb 100644 --- a/tools/diagnostics-app/src/library/powersync/DynamicSchemaManager.ts +++ b/tools/diagnostics-app/src/library/powersync/DynamicSchemaManager.ts @@ -1,12 +1,4 @@ -import { - Column, - ColumnType, - DBAdapter, - OpTypeEnum, - Schema, - SyncDataBatch, - Table -} from '@powersync/web'; +import { Column, ColumnType, DBAdapter, OpTypeEnum, Schema, SyncDataBatch, Table } from '@powersync/web'; import { AppSchema } from './AppSchema'; import { JsSchemaGenerator } from './JsSchemaGenerator'; @@ -30,14 +22,14 @@ export class DynamicSchemaManager { async updateFromOperations(batch: SyncDataBatch) { let schemaDirty = false; - for (let bucket of batch.buckets) { + for (const bucket of batch.buckets) { // Build schema - for (let op of bucket.data) { + for (const op of bucket.data) { if (op.op.value == OpTypeEnum.PUT && op.data != null) { this.tables[op.object_type!] ??= {}; const table = this.tables[op.object_type!]; const data = JSON.parse(op.data); - for (let [key, value] of Object.entries(data)) { + for (const [key, value] of Object.entries(data)) { if (key == 'id') { continue; } diff --git a/tools/diagnostics-app/src/library/powersync/RecordingStorageAdapter.ts b/tools/diagnostics-app/src/library/powersync/RecordingStorageAdapter.ts index 11eeef89..ef690085 100644 --- a/tools/diagnostics-app/src/library/powersync/RecordingStorageAdapter.ts +++ b/tools/diagnostics-app/src/library/powersync/RecordingStorageAdapter.ts @@ -24,7 +24,7 @@ export class RecordingStorageAdapter extends SqliteBucketStorage { async setTargetCheckpoint(checkpoint: Checkpoint) { await super.setTargetCheckpoint(checkpoint); await this.rdb.writeTransaction(async (tx) => { - for (let bucket of checkpoint.buckets) { + for (const bucket of checkpoint.buckets) { await tx.execute( `INSERT OR REPLACE INTO local_bucket_data(id, total_operations, last_op, download_size, downloading) VALUES ( @@ -53,7 +53,7 @@ export class RecordingStorageAdapter extends SqliteBucketStorage { await super.saveSyncData(batch); await this.rdb.writeTransaction(async (tx) => { - for (let bucket of batch.buckets) { + for (const bucket of batch.buckets) { // Record metrics const size = JSON.stringify(bucket.data).length; await tx.execute(