v0.2.0
livestorejs/livestorev0.2.0Nov 22, 2024by schickling
AI Summary
This release introduces a new query builder API to the core Livestore library, streamlining how queries are constructed. It features significant breaking changes, including the renaming of `querySQL` to `queryDb` and the removal of `rowQuery()`. Additionally, the React integration was updated to improve type safety and rename configuration options.
Key Highlights
- Added comprehensive query builder API with methods like `.select()`, `.where()`, `.orderBy()`, and `.count()`.
- Renamed `querySQL` to `queryDb` to support both raw SQL and the new query builder API.
- Improved React integration by making `useRow` type-safe for non-nullable columns.
- Renamed `options.defaultValues` to `options.insertValues` in React hooks.
Breaking Changes
- Renamed `querySQL` to `queryDb` and adjusted the signature to support both raw SQL and the new query builder API.
- Replaced `rowQuery()` with `table.query.row()`.
- Renamed `options.defaultValues` to `options.insertValues`.
- Removed `livestore/examples` repository in favor of `/examples/standalone`.
New Features
- New query builder API allowing fluent query construction with chaining support.
- Enhanced type safety for `useRow` hook regarding non-nullable columns.
- Unified `queryDb` function supporting both raw SQL queries and the new query builder.
Full Release Notes
### Core
- Added query builder API
```ts
const table = DbSchema.table('myTable', {
id: DbSchema.text({ primaryKey: true }),
name: DbSchema.text(),
})
table.query.select('name')
table.query.where('name', '==', 'Alice')
table.query.where({ name: 'Alice' })
table.query.orderBy('name', 'desc').offset(10).limit(10)
table.query.count().where('name', 'like', '%Ali%')
table.query.row('123', { insertValues: { name: 'Bob' } })
```
- Breaking: Renamed `querySQL` to `queryDb` and adjusted the signature to allow both the new query builder API and raw SQL queries:
```ts
// before
const query$ = querySQL(sql`select * from myTable where name = 'Alice'`, {
schema: Schema.Array(table.schema),
})
// after (raw SQL)
const query$ = queryDb({
query: sql`select * from myTable where name = 'Alice'`,
schema: Schema.Array(table.schema),
})
// or with the query builder API
const query$ = queryDb(table.query.select('name').where({ name: 'Alice' }))
```
- Breaking: Replaced `rowQuery()` with `table.query.row()` (as part of the new query builder API)
### React integration
- Fix: `useRow` now type-safe for non-nullable/non-default columns. Renamed `options.defaultValues` to `options.insertValues`
### Misc
- Removed Drizzle example in favour of new query builder API
- Removed `livestore/examples` repository in favour of `/examples/standalone` (additionally `/examples/src` for maintainers)