Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docs/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ It takes the following options as an object:
- `primaryKey: string[]`<br>
An array of column names that form the primary key of the table you are syncing into. Used for updates and deletes.

- `shapeKey: string`<br>
Optional identifier for the shape subscription - if provided the stream state will be persisted along with the data in order to allow resuming the stream between sessions.
- `shapeKey: string | null`<br>
Identifier for the shape subscription - If not null, stream state will be persisted along with the data in order to allow resuming the stream between sessions.

- `useCopy: boolean`<br>
Whether to use the `COPY FROM` command to insert the initial data, defaults to `false`. This process may be faster than inserting row by row as it combines the inserts into a CSV to be passed to Postgres.
Expand Down
4 changes: 2 additions & 2 deletions packages/pglite-sync/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface SyncShapeToTableOptions {
schema?: string
mapColumns?: MapColumns
primaryKey: string[]
shapeKey?: ShapeKey
shapeKey: ShapeKey | null
useCopy?: boolean
commitGranularity?: CommitGranularity
commitThrottle?: number
Expand Down Expand Up @@ -110,7 +110,7 @@ async function createPlugin(
shapePerTableLock.set(options.table)
let shapeSubState: ShapeSubscriptionState | null = null

// if shapeKey is provided, ensure persistence of shape subscription
// if shapeKey is not null, ensure persistence of shape subscription
// state is possible and check if it is already persisted
if (options.shapeKey) {
shapeSubState = await getShapeSubscriptionState({
Expand Down
15 changes: 15 additions & 0 deletions packages/pglite-sync/test/sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('pglite-sync', () => {
},
table: 'todo',
primaryKey: ['id'],
shapeKey: null
})

// insert
Expand Down Expand Up @@ -130,6 +131,7 @@ describe('pglite-sync', () => {
},
table: 'todo',
primaryKey: ['id'],
shapeKey: null
})

const numInserts = 10000
Expand Down Expand Up @@ -397,6 +399,7 @@ describe('pglite-sync', () => {
},
table: table,
primaryKey: ['id'],
shapeKey: null
})

// should throw if syncing more shapes into same table
Expand All @@ -409,6 +412,7 @@ describe('pglite-sync', () => {
},
table: table,
primaryKey: ['id'],
shapeKey: null
}),
).rejects.toThrowError(`Already syncing shape for table ${table}`)

Expand All @@ -420,6 +424,7 @@ describe('pglite-sync', () => {
},
table: altTable,
primaryKey: ['id'],
shapeKey: null
})
altShape.unsubscribe()

Expand All @@ -434,6 +439,7 @@ describe('pglite-sync', () => {
},
table: table,
primaryKey: ['id'],
shapeKey: null
})
shape2.unsubscribe()
})
Expand All @@ -454,6 +460,7 @@ describe('pglite-sync', () => {
},
table: 'todo',
primaryKey: ['id'],
shapeKey: null
})

// insert
Expand Down Expand Up @@ -543,6 +550,7 @@ describe('pglite-sync', () => {
},
table: 'test_syncing',
primaryKey: ['id'],
shapeKey: null
})

await feedMessage({
Expand Down Expand Up @@ -589,6 +597,7 @@ describe('pglite-sync', () => {
table: 'todo',
primaryKey: ['id'],
useCopy: true,
shapeKey: null
})

// Create a batch of insert messages followed by an update
Expand Down Expand Up @@ -668,6 +677,7 @@ describe('pglite-sync', () => {
table: 'todo',
primaryKey: ['id'],
useCopy: true,
shapeKey: null
})

const specialCharMessages: Message[] = [
Expand Down Expand Up @@ -765,6 +775,7 @@ describe('pglite-sync', () => {
table: 'todo',
primaryKey: ['id'],
commitGranularity: batchSize,
shapeKey: null
})

// Create test messages - 7 total (should see batch of 5, then 2)
Expand Down Expand Up @@ -956,6 +967,7 @@ describe('pglite-sync', () => {
table: 'todo',
primaryKey: ['id'],
commitGranularity: 'up-to-date',
shapeKey: null
})

// Send multiple messages
Expand Down Expand Up @@ -1035,6 +1047,7 @@ describe('pglite-sync', () => {
table: 'todo',
primaryKey: ['id'],
commitGranularity: 'operation',
shapeKey: null
})

// Send multiple messages
Expand Down Expand Up @@ -1120,6 +1133,7 @@ describe('pglite-sync', () => {
primaryKey: ['id'],
commitGranularity: 'operation',
commitThrottle: throttleMs,
shapeKey: null
})

// Send messages with 10ms delays between them
Expand Down Expand Up @@ -1209,6 +1223,7 @@ describe('pglite-sync', () => {
table: 'todo',
primaryKey: ['id'],
onInitialSync,
shapeKey: null
})

// Send some initial data
Expand Down
Loading