function localOnlyCollectionOptions<TExplicit, TSchema, TFallback, TKey>(config): object
function localOnlyCollectionOptions<TExplicit, TSchema, TFallback, TKey>(config): object
Defined in: packages/db/src/local-only.ts:137
Creates Local-only collection options for use with a standard Collection
This is an in-memory collection that doesn't sync with external sources but uses a loopback sync config that immediately "syncs" all optimistic changes to the collection, making them permanent. Perfect for local-only data that doesn't need persistence or external synchronization.
• TExplicit = unknown
The explicit type of items in the collection (highest priority)
• TSchema extends StandardSchemaV1<unknown, unknown> = never
The schema type for validation and type inference (second priority)
• TFallback extends Record<string, unknown> = Record<string, unknown>
The fallback type if no explicit or schema type is provided
• TKey extends string | number = string | number
The type of the key returned by getKey
LocalOnlyCollectionConfig<TExplicit, TSchema, TFallback, TKey>
Configuration options for the Local-only collection
object
Collection options with utilities (currently empty but follows the pattern)
gcTime: number = 0;
gcTime: number = 0;
getKey: (item) => TKey;
getKey: (item) => TKey;
ResolveType<TExplicit, TSchema, TFallback>
TKey
optional id: string;
optional id: string;
Standard Collection configuration properties
onDelete: (params) => Promise<any> = wrappedOnDelete;
onDelete: (params) => Promise<any> = wrappedOnDelete;
Wrapper for onDelete handler that also confirms the transaction immediately
DeleteMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>
Promise<any>
onInsert: (params) => Promise<any> = wrappedOnInsert;
onInsert: (params) => Promise<any> = wrappedOnInsert;
Create wrapper handlers that call user handlers first, then confirm transactions Wraps the user's onInsert handler to also confirm the transaction immediately
InsertMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>
Promise<any>
onUpdate: (params) => Promise<any> = wrappedOnUpdate;
onUpdate: (params) => Promise<any> = wrappedOnUpdate;
Wrapper for onUpdate handler that also confirms the transaction immediately
UpdateMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>
Promise<any>
optional schema: TSchema;
optional schema: TSchema;
startSync: boolean = true;
startSync: boolean = true;
sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, TKey> = syncResult.sync;
sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, TKey> = syncResult.sync;
utils: LocalOnlyCollectionUtils;
utils: LocalOnlyCollectionUtils;
// Basic local-only collection
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
})
)
// Basic local-only collection
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
})
)
// Local-only collection with initial data
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
initialData: [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
],
})
)
// Local-only collection with initial data
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
initialData: [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
],
})
)
// Local-only collection with mutation handlers
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
console.log('Item inserted:', transaction.mutations[0].modified)
// Custom logic after insert
},
})
)
// Local-only collection with mutation handlers
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
console.log('Item inserted:', transaction.mutations[0].modified)
// Custom logic after insert
},
})
)