Function: createQuerySync()

createQuerySync(args: { engine: Pick<LixEngine, "executeSync">; }): QuerySyncFunction

Create a synchronous query builder factory bound to an engine.

Returns a querySync(table) function that mirrors Kysely's selectFrom(table) builder, but with synchronous execution via .execute(), .executeTakeFirst(), and .executeTakeFirstOrThrow().

When to use

  • Inside plugins: pass the returned querySync into detectChanges() so plugins can read current state synchronously while computing changes.
  • In unit tests: construct querySync from an in‑process Lix (e.g. InMemoryEnvironment) using createQuerySync({ engine: lix.engine! }) and call your plugin's detectChanges({ querySync, ... }) directly.

Engine availability

  • In in‑process environments (like the default in‑memory environment), lix.engine is available and can be passed here.
  • In worker/remote environments, lix.engine is undefined on the host thread. In those cases, use integration tests that drive the file handlers or a test environment that exposes the engine.

JSON behavior

  • snapshot_content is parsed to objects to match normal Kysely queries. Other JSON columns are returned as raw JSON strings; parse if needed.

Example

// Unit testing a plugin's detectChanges directly
import { openLix, createQuerySync } from '@lix-js/sdk'
import { detectChanges } from '../src/detect-changes.js'

const lix = await openLix({})
const querySync = createQuerySync({ engine: lix.engine! })

const after = {
  id: 'file1',
  path: '/doc.md',
  data: new TextEncoder().encode('# Hello'),
  metadata: {}
}

const changes = detectChanges({ querySync, after })
expect(Array.isArray(changes)).toBe(true)

Parameters

ParameterType
args{ engine: Pick<LixEngine, "executeSync">; }
args.enginePick<LixEngine, "executeSync">

Returns

QuerySyncFunction