Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
0450cff
starting point...
samwillis Jun 18, 2025
7f6b55a
checkpoint
samwillis Jun 18, 2025
19b8749
checkpoint
samwillis Jun 18, 2025
e28ec03
tests
samwillis Jun 18, 2025
3c7ced9
more
samwillis Jun 18, 2025
7d03505
tidy
samwillis Jun 18, 2025
2211d48
checkpoint
samwillis Jun 19, 2025
5cc2b8a
more
samwillis Jun 19, 2025
d9cbd36
basic test of full build -> compile -> run
samwillis Jun 19, 2025
197e04a
checkpoint
samwillis Jun 19, 2025
85f6519
more
samwillis Jun 20, 2025
006898b
WIP groupby
samwillis Jun 20, 2025
c640cbf
groupby with having
samwillis Jun 21, 2025
f5118c0
fix lint errors
samwillis Jun 21, 2025
33f724e
fix lint warnings
samwillis Jun 21, 2025
e7f9cd5
fix tets
samwillis Jun 21, 2025
119d193
fix test type errors
samwillis Jun 21, 2025
9171963
fix lint
samwillis Jun 22, 2025
b4f0c2f
move tests
samwillis Jun 22, 2025
d6dc39c
fix return type for select
samwillis Jun 22, 2025
ffbc839
fix return type when no select
samwillis Jun 22, 2025
4ae3cba
fix lint errors
samwillis Jun 22, 2025
976bd07
update d2mini
samwillis Jun 22, 2025
f04e87f
Merge branch 'main' into query2
samwillis Jun 22, 2025
d1276bb
type tests
samwillis Jun 22, 2025
8d213dd
test for query with no select
samwillis Jun 22, 2025
b200a43
join tests
samwillis Jun 22, 2025
c76996f
tidy
samwillis Jun 22, 2025
a83e432
fix test
samwillis Jun 22, 2025
fe8e23b
fix join types
samwillis Jun 23, 2025
839a0e9
remove unused fn
samwillis Jun 23, 2025
2339381
move type tests out into test-d files
samwillis Jun 23, 2025
de646c0
tests for the query builder callback enspression builder types and fi…
samwillis Jun 23, 2025
29ab969
test subqueries
samwillis Jun 23, 2025
ea051af
fix types for refs and results in joins
samwillis Jun 23, 2025
2aba326
fix lint
samwillis Jun 23, 2025
7ef09d7
Merge branch 'main' into query2
samwillis Jun 23, 2025
4e51e94
fix after merge
samwillis Jun 23, 2025
2ba4cd6
enable use of spread in a select expression
samwillis Jun 24, 2025
bc85141
subquery compiling caching to dedupe
samwillis Jun 24, 2025
12dceae
simplify funciton sigs
samwillis Jun 24, 2025
b159b3a
compiling rather than evaluation of expressions
samwillis Jun 24, 2025
e011f5c
refactor compiled pipeline to have better structure
samwillis Jun 24, 2025
0c67aee
checkpoint before checking out cursor/implement-prd-proposals-and-run…
samwillis Jun 24, 2025
c7c80d3
Merge branch 'main' into query2
samwillis Jun 24, 2025
353e0fc
refactor orderby
samwillis Jun 24, 2025
4723520
fix tests
samwillis Jun 24, 2025
eb4ed13
remove old query engine
samwillis Jun 24, 2025
dcfc38d
tidy
samwillis Jun 24, 2025
f43ddd7
more tests
samwillis Jun 24, 2025
d58b12f
remove unused utils
samwillis Jun 24, 2025
b175c11
remove files
samwillis Jun 24, 2025
ec5f3c4
Merge branch 'main' into query2
samwillis Jun 26, 2025
460a153
incorporate collection lifecycle into live queries
samwillis Jun 26, 2025
6b7d116
ensure that live queries are not set to ready untill all their source…
samwillis Jun 26, 2025
c701c9a
port over missing change
samwillis Jun 26, 2025
c5dbf89
wip react useLiveQuery
samwillis Jun 26, 2025
87fe4f6
Merge branch 'main' into query2
samwillis Jun 26, 2025
44be0f6
wip tests
samwillis Jun 26, 2025
ffe3929
vue useLiveQuery WIP
samwillis Jun 26, 2025
702b915
tidy
samwillis Jun 26, 2025
deb731f
fix lint warnings
samwillis Jun 26, 2025
761954d
add a failing for for insert-update-delete with orderBy
samwillis Jun 26, 2025
02a6615
add a new rowUpdateMode option, fixes orderby
samwillis Jun 26, 2025
6dccf10
remove store dep
samwillis Jun 26, 2025
ab6835f
react useLiveQuery can be passed a collection
samwillis Jun 27, 2025
5c654ab
passing a collection to the react and vue useLiveQuery done
samwillis Jun 27, 2025
1a9f9ba
fix types
samwillis Jun 27, 2025
a315a5d
declutter type prompt in query builder
samwillis Jun 27, 2025
8e1368d
WIP functional variants of the select, where and having query builder…
samwillis Jun 28, 2025
59b065c
jsdoc for the query builder
samwillis Jun 28, 2025
c200ea8
remove alias in test for isIn
samwillis Jun 28, 2025
5d8f995
fix multiple where/having clauses
samwillis Jun 30, 2025
c485605
rename isIn to inArray
samwillis Jun 30, 2025
6435efa
wip change exmaple to use new query syntax
samwillis Jun 30, 2025
a8b7bdb
Merge branch 'main' into query2
samwillis Jun 30, 2025
04f8e50
fix type bug
samwillis Jun 30, 2025
d5a2afc
wip fixes to example
samwillis Jun 30, 2025
47bf1ff
bump d2mini to latest - fixes multi batch joins
samwillis Jun 30, 2025
029c3ad
ensure that the status is set before sending the batch of messages
samwillis Jun 30, 2025
b2e8e19
batch events from optimistic removal when applying sync
samwillis Jul 1, 2025
0bf575e
fix type errors in demo
samwillis Jul 1, 2025
a45f497
rename derived to optimistic
samwillis Jul 1, 2025
e0f31f1
make react useLiveQuery data and state values lazy
samwillis Jul 1, 2025
502b33e
make vue useLiveQuery more fine grade
samwillis Jul 1, 2025
24bdccd
fix linting
samwillis Jul 1, 2025
55b162d
update overview docs to use new syntax
samwillis Jul 3, 2025
4992c5f
tidy up map like methods
samwillis Jul 3, 2025
1b73361
use useSyncExternalStore for useLiveQuery (#225)
samwillis Jul 6, 2025
45bd564
Merge branch 'main' into query2
samwillis Jul 6, 2025
e125e90
post review changes
samwillis Jul 6, 2025
8b3086a
enable a `new Query.from(...) syntax
samwillis Jul 7, 2025
71bae50
add an isReady on the framework hooks
samwillis Jul 7, 2025
ea72caf
Merge remote-tracking branch 'origin/main' into samwillis/is-ready-on…
KyleAMathews Jul 7, 2025
7d9fd3e
add an isReady on the framework hooks
samwillis Jul 7, 2025
9a4822c
update booleans
KyleAMathews Jul 7, 2025
6b07cfa
update react tests
KyleAMathews Jul 7, 2025
4f857e0
don't default to no watch
KyleAMathews Jul 7, 2025
c90c8ac
Update useLiveQuery.test.tsx
KyleAMathews Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/db/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ export class CollectionImpl<
Array<CollectionStatus>
> = {
idle: [`loading`, `error`, `cleaned-up`],
loading: [`ready`, `error`, `cleaned-up`],
loading: [`initialCommit`, `error`, `cleaned-up`],
initialCommit: [`ready`, `error`, `cleaned-up`],
ready: [`cleaned-up`, `error`],
error: [`cleaned-up`, `idle`],
"cleaned-up": [`loading`, `error`],
Expand Down Expand Up @@ -382,14 +383,18 @@ export class CollectionImpl<

pendingTransaction.committed = true

// Update status to ready
// We do this before committing as we want the events from the changes to
// be from a "ready" state.
// Update status to initialCommit when transitioning from loading
// This indicates we're in the process of committing the first transaction
if (this._status === `loading`) {
this.setStatus(`ready`)
this.setStatus(`initialCommit`)
}

this.commitPendingTransactions()

// Transition from initialCommit to ready after the first commit is complete
if (this._status === `initialCommit`) {
this.setStatus(`ready`)
}
},
})

Expand Down
3 changes: 2 additions & 1 deletion packages/db/src/query/live-query-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export function liveQueryCollectionOptions<

const allCollectionsReady = () => {
return Object.values(collections).every(
(collection) => collection.status === `ready`
(collection) =>
collection.status === `ready` || collection.status === `initialCommit`
)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/db/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ export type CollectionStatus =
| `idle`
/** Sync has started but hasn't received the first commit yet */
| `loading`
/** Collection is in the process of committing its first transaction */
| `initialCommit`
/** Collection has received at least one commit and is ready for use */
| `ready`
/** An error occurred during sync initialization */
Expand Down
19 changes: 18 additions & 1 deletion packages/db/tests/collection-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe(`Collection Error Handling`, () => {

// Valid transitions from loading
expect(() =>
collectionImpl.validateStatusTransition(`loading`, `ready`)
collectionImpl.validateStatusTransition(`loading`, `initialCommit`)
).not.toThrow()
expect(() =>
collectionImpl.validateStatusTransition(`loading`, `error`)
Expand All @@ -369,6 +369,17 @@ describe(`Collection Error Handling`, () => {
collectionImpl.validateStatusTransition(`loading`, `cleaned-up`)
).not.toThrow()

// Valid transitions from initialCommit
expect(() =>
collectionImpl.validateStatusTransition(`initialCommit`, `ready`)
).not.toThrow()
expect(() =>
collectionImpl.validateStatusTransition(`initialCommit`, `error`)
).not.toThrow()
expect(() =>
collectionImpl.validateStatusTransition(`initialCommit`, `cleaned-up`)
).not.toThrow()

// Valid transitions from ready
expect(() =>
collectionImpl.validateStatusTransition(`ready`, `cleaned-up`)
Expand Down Expand Up @@ -397,6 +408,12 @@ describe(`Collection Error Handling`, () => {
expect(() =>
collectionImpl.validateStatusTransition(`idle`, `idle`)
).not.toThrow()
expect(() =>
collectionImpl.validateStatusTransition(
`initialCommit`,
`initialCommit`
)
).not.toThrow()
expect(() =>
collectionImpl.validateStatusTransition(`ready`, `ready`)
).not.toThrow()
Expand Down
27 changes: 27 additions & 0 deletions packages/react-db/src/useLiveQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useRef, useSyncExternalStore } from "react"
import { createLiveQueryCollection } from "@tanstack/db"
import type {
Collection,
CollectionStatus,
Context,
GetResult,
InitialQueryBuilder,
Expand All @@ -17,6 +18,12 @@ export function useLiveQuery<TContext extends Context>(
state: Map<string | number, GetResult<TContext>>
data: Array<GetResult<TContext>>
collection: Collection<GetResult<TContext>, string | number, {}>
status: CollectionStatus
isLoading: boolean
isReady: boolean
isIdle: boolean
isError: boolean
isCleanedUp: boolean
}

// Overload 2: Accept config object
Expand All @@ -27,6 +34,12 @@ export function useLiveQuery<TContext extends Context>(
state: Map<string | number, GetResult<TContext>>
data: Array<GetResult<TContext>>
collection: Collection<GetResult<TContext>, string | number, {}>
status: CollectionStatus
isLoading: boolean
isReady: boolean
isIdle: boolean
isError: boolean
isCleanedUp: boolean
}

// Overload 3: Accept pre-created live query collection
Expand All @@ -40,6 +53,12 @@ export function useLiveQuery<
state: Map<TKey, TResult>
data: Array<TResult>
collection: Collection<TResult, TKey, TUtils>
status: CollectionStatus
isLoading: boolean
isReady: boolean
isIdle: boolean
isError: boolean
isCleanedUp: boolean
}

// Implementation - use function overloads to infer the actual collection type
Expand Down Expand Up @@ -171,5 +190,13 @@ export function useLiveQuery(
state: snapshot.state,
data: snapshot.data,
collection: snapshot.collection,
status: snapshot.collection.status,
isLoading:
snapshot.collection.status === `loading` ||
snapshot.collection.status === `initialCommit`,
isReady: snapshot.collection.status === `ready`,
isIdle: snapshot.collection.status === `idle`,
isError: snapshot.collection.status === `error`,
isCleanedUp: snapshot.collection.status === `cleaned-up`,
}
}
Loading