Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2fb394f
Add nested object query tests for TanStack DB
KyleAMathews Jul 31, 2025
f44031d
checkpoint
samwillis Aug 7, 2025
57ec777
checkpoint
samwillis Aug 7, 2025
9f57dd6
checkpoint
samwillis Aug 7, 2025
e96bafd
checkpoint
samwillis Aug 7, 2025
3b26333
checkpoint
samwillis Aug 7, 2025
efa4b13
checkpoint
samwillis Aug 7, 2025
9f12edb
checkpoint
samwillis Aug 7, 2025
d5921a4
checkpoint
samwillis Aug 7, 2025
6c56f1d
checkpoint
samwillis Aug 7, 2025
046ad7d
checkpoint
samwillis Aug 7, 2025
9ca2797
checkpoint
samwillis Aug 7, 2025
818cd7b
checkpoint
samwillis Aug 7, 2025
7a077a8
checkpoint
samwillis Aug 7, 2025
ae11e1d
checkpoint
samwillis Aug 7, 2025
9f8b947
tests and lint pass!!
samwillis Aug 7, 2025
c3a305e
changeset
samwillis Aug 7, 2025
cfb0b9e
improve ref types in ide
samwillis Aug 10, 2025
73ea1ee
tidy
samwillis Aug 11, 2025
110f9d6
tidy functions
samwillis Aug 11, 2025
bec6ea5
wip review fixes
samwillis Aug 26, 2025
ec34933
finish changes from review
samwillis Aug 26, 2025
ac8809b
test
samwillis Aug 26, 2025
3643e9c
Merge branch 'main' into ref-refactor
samwillis Aug 26, 2025
8eae2a8
fix tests after merging in main - they were missing optionality handling
samwillis Aug 26, 2025
39570bc
Merge branch 'main' into ref-refactor
samwillis Sep 4, 2025
514ed2e
change changeset to minor version bump
samwillis Sep 8, 2025
eae3c3e
Merge branch 'main' into ref-refactor
samwillis Sep 8, 2025
d08093f
fix test
samwillis Sep 8, 2025
d04109c
Merge branch 'main' into ref-refactor
samwillis Sep 8, 2025
5155882
fix test
samwillis Sep 8, 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
Prev Previous commit
Next Next commit
checkpoint
  • Loading branch information
samwillis committed Aug 7, 2025
commit 9f57dd6ecf7805f4e93d879fcf1eccc557baf46b
13 changes: 7 additions & 6 deletions packages/db/src/query/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
GroupByCallback,
JoinOnCallback,
MergeContext,
MergeContextForJoinCallback,
MergeContextWithJoinType,
OrderByCallback,
OrderByOptions,
Expand Down Expand Up @@ -142,7 +143,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
>(
source: TSource,
onCallback: JoinOnCallback<
MergeContext<TContext, SchemaFromSource<TSource>>
MergeContextForJoinCallback<TContext, SchemaFromSource<TSource>>
>,
type: TJoinType = `left` as TJoinType
): QueryBuilder<
Expand All @@ -154,7 +155,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
const currentAliases = this._getCurrentAliases()
const newAliases = [...currentAliases, alias]
const refProxy = createRefProxy(newAliases) as RefProxyForContext<
MergeContext<TContext, SchemaFromSource<TSource>>
MergeContextForJoinCallback<TContext, SchemaFromSource<TSource>>
>

// Get the join condition expression
Expand Down Expand Up @@ -209,7 +210,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
leftJoin<TSource extends Source>(
source: TSource,
onCallback: JoinOnCallback<
MergeContext<TContext, SchemaFromSource<TSource>>
MergeContextForJoinCallback<TContext, SchemaFromSource<TSource>>
>
): QueryBuilder<
MergeContextWithJoinType<TContext, SchemaFromSource<TSource>, `left`>
Expand All @@ -235,7 +236,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
rightJoin<TSource extends Source>(
source: TSource,
onCallback: JoinOnCallback<
MergeContext<TContext, SchemaFromSource<TSource>>
MergeContextForJoinCallback<TContext, SchemaFromSource<TSource>>
>
): QueryBuilder<
MergeContextWithJoinType<TContext, SchemaFromSource<TSource>, `right`>
Expand All @@ -261,7 +262,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
innerJoin<TSource extends Source>(
source: TSource,
onCallback: JoinOnCallback<
MergeContext<TContext, SchemaFromSource<TSource>>
MergeContextForJoinCallback<TContext, SchemaFromSource<TSource>>
>
): QueryBuilder<
MergeContextWithJoinType<TContext, SchemaFromSource<TSource>, `inner`>
Expand All @@ -287,7 +288,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
fullJoin<TSource extends Source>(
source: TSource,
onCallback: JoinOnCallback<
MergeContext<TContext, SchemaFromSource<TSource>>
MergeContextForJoinCallback<TContext, SchemaFromSource<TSource>>
>
): QueryBuilder<
MergeContextWithJoinType<TContext, SchemaFromSource<TSource>, `full`>
Expand Down
16 changes: 16 additions & 0 deletions packages/db/src/query/builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,22 @@ export type MergeContext<
TNewSchema extends ContextSchema,
> = MergeContextWithJoinType<TContext, TNewSchema, `left`>

// Type for join callbacks that doesn't apply optionality - both tables are available
export type MergeContextForJoinCallback<
TContext extends Context,
TNewSchema extends ContextSchema,
> = {
baseSchema: TContext[`baseSchema`]
// Merge schemas without applying join optionality - both are non-optional in join condition
schema: TContext[`schema`] & TNewSchema
fromSourceName: TContext[`fromSourceName`]
hasJoins: true
joinTypes: TContext[`joinTypes`] extends Record<string, any>
? TContext[`joinTypes`]
: {}
result: TContext[`result`]
}

// Helper type for updating context with result type
export type WithResult<TContext extends Context, TResult> = Prettify<
Omit<TContext, `result`> & {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/tests/query/builder/functional-variants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe(`QueryBuilder functional variants (fn)`, () => {
({ employees, departments }) =>
eq(employees.department_id, departments.id)
)
.groupBy(({ departments }) => departments.name)
.groupBy(({ departments }) => departments?.name)
.fn.having(
(row) =>
row.employees.salary > 60000 &&
Expand All @@ -245,7 +245,7 @@ describe(`QueryBuilder functional variants (fn)`, () => {
)
.fn.where((row) => row.employees.active)
.fn.where((row) => row.employees.salary > 40000)
.groupBy(({ departments }) => departments.name)
.groupBy(({ departments }) => departments?.name)
.fn.having((row) => row.employees.salary > 70000)
.fn.select((row) => ({
departmentName: row.departments?.name || `Unknown`,
Expand Down
4 changes: 2 additions & 2 deletions packages/db/tests/query/builder/join.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe(`QueryBuilder.join`, () => {
eq(employees.department_id, departments.id)
)
.join({ projects: projectsCollection }, ({ departments, projects }) =>
eq(departments.id, projects.department_id)
eq(departments?.id, projects?.department_id)
)

const builtQuery = getQueryIR(query)
Expand Down Expand Up @@ -360,7 +360,7 @@ describe(`QueryBuilder.join`, () => {
.innerJoin(
{ projects: projectsCollection },
({ departments, projects }) =>
eq(departments.id, projects.department_id)
eq(departments?.id, projects.department_id)
)

const builtQuery = getQueryIR(query)
Expand Down