Skip to content

Trait

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:94

TName extends string

TType

TEncoded

TOptions extends ClientDocumentTableOptions<TType>

readonly [ClientDocumentTableDefSymbol]: object

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:165

readonly derived: object

readonly setEventDef: SetEventDef<TName, TType, TOptions>

readonly setMaterializer: Materializer<SetEventDef<TName, TType, TOptions>>

readonly options: TOptions


readonly default: TOptions["default"]

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:164


readonly get: MakeGetQueryBuilder<TName, TType, TOptions>

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:123

Get the current value of the client document table.

const someDocumentTable = State.SQLite.clientDocument({
name: 'SomeDocumentTable',
schema: Schema.Struct({
someField: Schema.String,
}),
default: { value: { someField: 'some-value' } },
})
const value$ = queryDb(someDocumentTable.get('some-id'))
// When you've set a default id, you can omit the id argument
const uiState = State.SQLite.clientDocument({
name: 'UiState',
schema: Schema.Struct({
someField: Schema.String,
}),
default: { id: SessionIdSymbol, value: { someField: 'some-value' } },
})
const value$ = queryDb(uiState.get())

readonly set: SetEventDefLike<TName, TType, TOptions>

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:161

Derived event definition for setting the value of the client document table. If the document doesn’t exist yet, the first .set event will create it.

const someDocumentTable = State.SQLite.clientDocument({
name: 'SomeDocumentTable',
schema: Schema.Struct({
someField: Schema.String,
someOtherField: Schema.String,
}),
default: { value: { someField: 'some-default-value', someOtherField: 'some-other-default-value' } },
})
const setEventDef = store.commit(someDocumentTable.set({ someField: 'explicit-value' }, 'some-id'))
// Will commit an event with the following payload:
// { id: 'some-id', value: { someField: 'explicit-value', someOtherField: 'some-other-default-value' } }

Similar to .get, you can omit the id argument if you’ve set a default id.

const uiState = State.SQLite.clientDocument({
name: 'UiState',
schema: Schema.Struct({ someField: Schema.String }),
default: { id: SessionIdSymbol, value: { someField: 'some-default-value' } },
})
const setEventDef = store.commit(uiState.set({ someField: 'explicit-value' }))
// Will commit an event with the following payload:
// { id: '...', value: { someField: 'explicit-value' } }
// ^^^
// Automatically replaced with the client session id

readonly Value: TType

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:162


readonly valueSchema: Schema<TType, TEncoded>

Defined in: packages/@livestore/common/dist/schema/state/sqlite/client-document-def.d.ts:163