-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
246bf58
commit 9438f3b
Showing
10 changed files
with
3,380 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { DeleteQueryBuilder } from '../query-builder/delete-query-builder.js' | ||
import type { DeleteResult } from '../query-builder/delete-result.js' | ||
import type { ShallowRecord } from '../util/type-utils.js' | ||
import type { | ||
ExtractTableAlias, | ||
From, | ||
FromTables, | ||
TableExpressionOrList, | ||
} from './table-parser.js' | ||
|
||
export type DeleteFrom<DB, TE extends TableExpressionOrList<DB, never>> = | ||
TE extends ReadonlyArray<infer T> | ||
? DeleteQueryBuilder<From<DB, T>, FromTables<DB, never, T>, DeleteResult> | ||
: TE extends keyof DB & string | ||
? // This branch creates a good-looking type for the most common case: | ||
// deleteFrom('person') --> DeleteQueryBuilder<DB, 'person', {}>. | ||
// ExtractTableAlias is needed for the case where DB == any. Without it: | ||
// deleteFrom('person as p') --> DeleteQueryBuilder<DB, 'person as p', {}> | ||
DeleteQueryBuilder<DB, ExtractTableAlias<DB, TE>, DeleteResult> | ||
: // This branch creates a good-looking type for common aliased case: | ||
// deleteFrom('person as p') --> DeleteQueryBuilder<DB & { p: Person }, 'p', {}>. | ||
TE extends `${infer T} as ${infer A}` | ||
? T extends keyof DB | ||
? DeleteQueryBuilder<DB & ShallowRecord<A, DB[T]>, A, DeleteResult> | ||
: never | ||
: DeleteQueryBuilder< | ||
From<DB, TE>, | ||
FromTables<DB, never, TE>, | ||
DeleteResult | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { MergeQueryBuilder } from '../query-builder/merge-query-builder.js' | ||
import type { MergeResult } from '../query-builder/merge-result.js' | ||
import type { ShallowRecord } from '../util/type-utils.js' | ||
import type { ExtractTableAlias, SimpleTableReference } from './table-parser.js' | ||
|
||
export type MergeInto< | ||
DB, | ||
TE extends SimpleTableReference<DB>, | ||
> = TE extends keyof DB & string | ||
? MergeQueryBuilder<DB, ExtractTableAlias<DB, TE>, MergeResult> | ||
: TE extends `${infer T} as ${infer A}` | ||
? T extends keyof DB | ||
? MergeQueryBuilder<DB & ShallowRecord<A, DB[T]>, A, MergeResult> | ||
: never | ||
: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { SelectQueryBuilder } from '../query-builder/select-query-builder.js' | ||
import type { ShallowRecord } from '../util/type-utils.js' | ||
import type { | ||
ExtractTableAlias, | ||
From, | ||
FromTables, | ||
TableExpressionOrList, | ||
} from './table-parser.js' | ||
|
||
export type SelectFrom< | ||
DB, | ||
TB extends keyof DB, | ||
TE extends TableExpressionOrList<DB, TB>, | ||
> = | ||
TE extends ReadonlyArray<infer T> | ||
? SelectQueryBuilder<From<DB, T>, FromTables<DB, TB, T>, {}> | ||
: TE extends keyof DB & string | ||
? // This branch creates a good-looking type for the most common case: | ||
// selectFrom('person') --> SelectQueryBuilder<DB, 'person', {}>. | ||
// ExtractTableAlias is needed for the case where DB == any. Without it: | ||
// selectFrom('person as p') --> SelectQueryBuilder<DB, 'person as p', {}> | ||
SelectQueryBuilder<DB, TB | ExtractTableAlias<DB, TE>, {}> | ||
: // This branch creates a good-looking type for common aliased case: | ||
// selectFrom('person as p') --> SelectQueryBuilder<DB & { p: Person }, 'p', {}>. | ||
TE extends `${infer T} as ${infer A}` | ||
? T extends keyof DB | ||
? SelectQueryBuilder<DB & ShallowRecord<A, DB[T]>, TB | A, {}> | ||
: never | ||
: SelectQueryBuilder<From<DB, TE>, FromTables<DB, TB, TE>, {}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { UpdateQueryBuilder } from '../query-builder/update-query-builder.js' | ||
import type { UpdateResult } from '../query-builder/update-result.js' | ||
import type { ShallowRecord } from '../util/type-utils.js' | ||
import type { | ||
ExtractTableAlias, | ||
From, | ||
FromTables, | ||
TableExpressionOrList, | ||
} from './table-parser.js' | ||
|
||
export type UpdateTable<DB, TE extends TableExpressionOrList<DB, never>> = | ||
TE extends ReadonlyArray<infer T> | ||
? UpdateQueryBuilder< | ||
From<DB, T>, | ||
FromTables<DB, never, T>, | ||
FromTables<DB, never, T>, | ||
UpdateResult | ||
> | ||
: TE extends keyof DB & string | ||
? // This branch creates a good-looking type for the most common case: | ||
// updateTable('person') --> UpdateQueryBuilder<DB, 'person', 'person', {}>. | ||
// ExtractTableAlias is needed for the case where DB == any. Without it: | ||
// updateTable('person as p') --> UpdateQueryBuilder<DB, 'person as p', 'person as p', {}> | ||
UpdateQueryBuilder< | ||
DB, | ||
ExtractTableAlias<DB, TE>, | ||
ExtractTableAlias<DB, TE>, | ||
UpdateResult | ||
> | ||
: // This branch creates a good-looking type for common aliased case: | ||
// updateTable('person as p') --> UpdateQueryBuilder<DB & { p: Person }, 'p', 'p', {}>. | ||
TE extends `${infer T} as ${infer A}` | ||
? T extends keyof DB | ||
? UpdateQueryBuilder<DB & ShallowRecord<A, DB[T]>, A, A, UpdateResult> | ||
: never | ||
: UpdateQueryBuilder< | ||
From<DB, TE>, | ||
FromTables<DB, never, TE>, | ||
FromTables<DB, never, TE>, | ||
UpdateResult | ||
> |
Oops, something went wrong.