ApiFull
ApiFull<
TResult,TTableDef,TWithout> =object
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:130
Type Parameters
Section titled “Type Parameters”TResult
Section titled “TResult”TResult
TTableDef
Section titled “TTableDef”TTableDef extends TableDefBase
TWithout
Section titled “TWithout”TWithout extends ApiFeature
Properties
Section titled “Properties”count()
Section titled “count()”
readonlycount: () =>QueryBuilder<number,TTableDef,TWithout|"row"|"count"|"select"|"orderBy"|"first"|"offset"|"limit"|"returning"|"onConflict">
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:175
Example:
db.todos.count()db.todos.count().where('completed', true)Returns
Section titled “Returns”QueryBuilder<number, TTableDef, TWithout | "row" | "count" | "select" | "orderBy" | "first" | "offset" | "limit" | "returning" | "onConflict">
delete()
Section titled “delete()”
readonlydelete: () =>QueryBuilder<TResult,TTableDef,TWithout|"row"|"select"|"count"|"orderBy"|"first"|"offset"|"limit"|"onConflict">
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:274
Delete rows from the table that match the where clause
Example:
db.todos.delete().where({ status: 'completed' })Note that it’s generally recommended to do soft-deletes for synced apps.
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "row" | "select" | "count" | "orderBy" | "first" | "offset" | "limit" | "onConflict">
first()
Section titled “first()”
readonlyfirst: <TFallback>(options?) =>QueryBuilder<TFallback|GetSingle<TResult>,TTableDef,TWithout|"row"|"first"|"orderBy"|"select"|"limit"|"offset"|"where"|"returning"|"onConflict">
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:209
Example:
db.todos.first()db.todos.where('id', '123').first()Query will throw if no rows are returned and no fallback is provided.
Type Parameters
Section titled “Type Parameters”TFallback
Section titled “TFallback”TFallback = never
Parameters
Section titled “Parameters”options?
Section titled “options?”fallback?
Section titled “fallback?”() => TFallback | GetSingle<TResult> | "throws"
Default
'throws'Returns
Section titled “Returns”QueryBuilder<TFallback | GetSingle<TResult>, TTableDef, TWithout | "row" | "first" | "orderBy" | "select" | "limit" | "offset" | "where" | "returning" | "onConflict">
insert()
Section titled “insert()”
readonlyinsert: (values) =>QueryBuilder<TResult,TTableDef,TWithout|"row"|"select"|"count"|"orderBy"|"first"|"offset"|"limit"|"where">
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:221
Insert a new row into the table
Example:
db.todos.insert({ id: '123', text: 'Buy milk', status: 'active' })Parameters
Section titled “Parameters”values
Section titled “values”TTableDef["insertSchema"]["Type"]
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "row" | "select" | "count" | "orderBy" | "first" | "offset" | "limit" | "where">
limit()
Section titled “limit()”
readonlylimit: (limit) =>QueryBuilder<TResult,TTableDef,TWithout|"row"|"limit"|"offset"|"first"|"orderBy"|"returning"|"onConflict">
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:199
Example:
db.todos.limit(10)Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "row" | "limit" | "offset" | "first" | "orderBy" | "returning" | "onConflict">
offset()
Section titled “offset()”
readonlyoffset: (offset) =>QueryBuilder<TResult,TTableDef,TWithout|"row"|"offset"|"orderBy"|"returning"|"onConflict">
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:192
Example:
db.todos.offset(10)Parameters
Section titled “Parameters”offset
Section titled “offset”number
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "row" | "offset" | "orderBy" | "returning" | "onConflict">
onConflict()
Section titled “onConflict()”
readonlyonConflict: {<TTarget>(target,action):QueryBuilder<TResult,TTableDef,TWithout|"select"|"where"|"count"|"orderBy"|"offset"|"limit"|"first"|"row">; <TTarget>(target,action,updateValues):QueryBuilder<TResult,TTableDef,TWithout|"select"|"where"|"count"|"orderBy"|"offset"|"limit"|"first"|"row">; }
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:240
Example: If the row already exists, it will be ignored.
db.todos.insert({ id: '123', text: 'Buy milk', status: 'active' }).onConflict('id', 'ignore')Example: If the row already exists, it will be replaced.
db.todos.insert({ id: '123', text: 'Buy milk', status: 'active' }).onConflict('id', 'replace')Example: If the row already exists, it will be updated.
db.todos.insert({ id: '123', text: 'Buy milk', status: 'active' }).onConflict('id', 'update', { text: 'Buy soy milk' })NOTE This API doesn’t yet support composite primary keys.
Call Signature
Section titled “Call Signature”<
TTarget>(target,action):QueryBuilder<TResult,TTableDef,TWithout|"select"|"where"|"count"|"orderBy"|"offset"|"limit"|"first"|"row">
Type Parameters
Section titled “Type Parameters”TTarget
Section titled “TTarget”TTarget extends string | number | symbol | readonly keyof TTableDef["sqliteDef"]["columns"][]
Parameters
Section titled “Parameters”target
Section titled “target”TTarget
action
Section titled “action”"ignore" | "replace"
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "select" | "where" | "count" | "orderBy" | "offset" | "limit" | "first" | "row">
Call Signature
Section titled “Call Signature”<
TTarget>(target,action,updateValues):QueryBuilder<TResult,TTableDef,TWithout|"select"|"where"|"count"|"orderBy"|"offset"|"limit"|"first"|"row">
Type Parameters
Section titled “Type Parameters”TTarget
Section titled “TTarget”TTarget extends string | number | symbol | readonly keyof TTableDef["sqliteDef"]["columns"][]
Parameters
Section titled “Parameters”target
Section titled “target”TTarget
action
Section titled “action”"update"
updateValues
Section titled “updateValues”Partial<TTableDef["rowSchema"]["Type"]>
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "select" | "where" | "count" | "orderBy" | "offset" | "limit" | "first" | "row">
orderBy()
Section titled “orderBy()”
readonlyorderBy: {<TColName>(col,direction):QueryBuilder<TResult,TTableDef,TWithout|"onConflict"|"returning">; <TParams>(params):QueryBuilder<TResult,TTableDef,TWithout|"onConflict"|"returning">; }
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:182
Example:
db.todos.orderBy('createdAt', 'desc')Call Signature
Section titled “Call Signature”<
TColName>(col,direction):QueryBuilder<TResult,TTableDef,TWithout|"onConflict"|"returning">
Type Parameters
Section titled “Type Parameters”TColName
Section titled “TColName”TColName extends string
Parameters
Section titled “Parameters”TColName
direction
Section titled “direction”"asc" | "desc"
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "onConflict" | "returning">
Call Signature
Section titled “Call Signature”<
TParams>(params):QueryBuilder<TResult,TTableDef,TWithout|"onConflict"|"returning">
Type Parameters
Section titled “Type Parameters”TParams
Section titled “TParams”TParams extends OrderByParams<TTableDef>
Parameters
Section titled “Parameters”params
Section titled “params”TParams
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "onConflict" | "returning">
returning()
Section titled “returning()”
readonlyreturning: <TColumns>(…columns) =>QueryBuilder<ReadonlyArray<{ readonly [K in TColumns]: TTableDef["sqliteDef"]["columns"][K]["schema"]["Type"] }>,TTableDef>
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:252
Similar to the .select API but for write queries (insert, update, delete).
Example:
db.todos.insert({ id: '123', text: 'Buy milk', status: 'active' }).returning('id')Type Parameters
Section titled “Type Parameters”TColumns
Section titled “TColumns”TColumns extends keyof TTableDef["sqliteDef"]["columns"] & string
Parameters
Section titled “Parameters”columns
Section titled “columns”…TColumns[]
Returns
Section titled “Returns”QueryBuilder<ReadonlyArray<{ readonly [K in TColumns]: TTableDef["sqliteDef"]["columns"][K]["schema"]["Type"] }>, TTableDef>
select()
Section titled “select()”
readonlyselect: {<TColumn>(pluckColumn):QueryBuilder<readonlyTTableDef["sqliteDef"]["columns"][TColumn]["schema"]["Type"][],TTableDef,TWithout|"select"|"onConflict"|"returning"|"row">; <TColumns>(…columns):QueryBuilder<readonly{ readonly [K in string]: TTableDef["sqliteDef"]["columns"][K]["schema"]["Type"] }[],TTableDef,TWithout|"select"|"count"|"onConflict"|"returning"|"row">; }
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:140
SELECT * is the default
Example:
db.todos.select('id', 'text', 'completed')db.todos.select('id')Call Signature
Section titled “Call Signature”<
TColumn>(pluckColumn):QueryBuilder<readonlyTTableDef["sqliteDef"]["columns"][TColumn]["schema"]["Type"][],TTableDef,TWithout|"select"|"onConflict"|"returning"|"row">
Selects and plucks a single column
Type Parameters
Section titled “Type Parameters”TColumn
Section titled “TColumn”TColumn extends string
Parameters
Section titled “Parameters”pluckColumn
Section titled “pluckColumn”TColumn
Returns
Section titled “Returns”QueryBuilder<readonly TTableDef["sqliteDef"]["columns"][TColumn]["schema"]["Type"][], TTableDef, TWithout | "select" | "onConflict" | "returning" | "row">
Call Signature
Section titled “Call Signature”<
TColumns>(…columns):QueryBuilder<readonly{ readonly [K in string]: TTableDef["sqliteDef"]["columns"][K]["schema"]["Type"] }[],TTableDef,TWithout|"select"|"count"|"onConflict"|"returning"|"row">
Select multiple columns
Type Parameters
Section titled “Type Parameters”TColumns
Section titled “TColumns”TColumns extends string
Parameters
Section titled “Parameters”columns
Section titled “columns”…TColumns[]
Returns
Section titled “Returns”QueryBuilder<readonly { readonly [K in string]: TTableDef["sqliteDef"]["columns"][K]["schema"]["Type"] }[], TTableDef, TWithout | "select" | "count" | "onConflict" | "returning" | "row">
update()
Section titled “update()”
readonlyupdate: (values) =>QueryBuilder<TResult,TTableDef,TWithout|"row"|"select"|"count"|"orderBy"|"first"|"offset"|"limit"|"onConflict">
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:263
Update rows in the table that match the where clause
Example:
db.todos.update({ status: 'completed' }).where({ id: '123' })Parameters
Section titled “Parameters”values
Section titled “values”Partial<TTableDef["rowSchema"]["Type"]>
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "row" | "select" | "count" | "orderBy" | "first" | "offset" | "limit" | "onConflict">
where()
Section titled “where()”
readonlywhere: {(params):QueryBuilder<TResult,TTableDef,TWithout|"select"|"row">; <TColName>(col,value):QueryBuilder<TResult,TTableDef,TWithout|"select"|"row">; <TColName>(col,op,value):QueryBuilder<TResult,TTableDef,TWithout|"select"|"row">; }
Defined in: packages/@livestore/common/dist/schema/state/sqlite/query-builder/api.d.ts:163
Notes:
- All where clauses are
ANDed together by default. nullvalues only support=and!=which is translated toIS NULLandIS NOT NULL.
Example:
db.todos.where('completed', true)db.todos.where('completed', '!=', true)db.todos.where({ completed: true })db.todos.where({ completed: { op: '!=', value: true } })TODO: Also support OR
Call Signature
Section titled “Call Signature”(
params):QueryBuilder<TResult,TTableDef,TWithout|"select"|"row">
Parameters
Section titled “Parameters”params
Section titled “params”Partial<{ [K in string | number | symbol]: undefined | TTableDef[“sqliteDef”][“columns”][K][“schema”][“Type”] | { op: SingleValue; value: (…)[(…)][“columns”][K][“schema”][“Type”] } | { op: MultiValue; value: ReadonlyArray<(…)[(…)][K][“schema”][“Type”]> } }>
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "select" | "row">
Call Signature
Section titled “Call Signature”<
TColName>(col,value):QueryBuilder<TResult,TTableDef,TWithout|"select"|"row">
Type Parameters
Section titled “Type Parameters”TColName
Section titled “TColName”TColName extends string | number | symbol
Parameters
Section titled “Parameters”TColName
TTableDef["sqliteDef"]["columns"][TColName]["schema"]["Type"]
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "select" | "row">
Call Signature
Section titled “Call Signature”<
TColName>(col,op,value):QueryBuilder<TResult,TTableDef,TWithout|"select"|"row">
Type Parameters
Section titled “Type Parameters”TColName
Section titled “TColName”TColName extends string | number | symbol
Parameters
Section titled “Parameters”TColName
TTableDef["sqliteDef"]["columns"][TColName]["schema"]["Type"]
Returns
Section titled “Returns”QueryBuilder<TResult, TTableDef, TWithout | "select" | "row">