-
Notifications
You must be signed in to change notification settings - Fork 649
Typescript query builder #3630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jsdt
wants to merge
22
commits into
master
Choose a base branch
from
jsdt/ts-query-builder-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Typescript query builder #3630
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7aa4d8a
Fix multicolumn indexes for typescript modules
jsdt 395962b
Add an assertion for unindexed columns.
jsdt 6d04c4d
Fix lint issues.
jsdt e9d83a7
WIP on rewrite. RowExpr looks right, indexes aren't working yet
jsdt e4bcc8b
Make sure we only autocomplete real indexes
jsdt 1a8e83b
WIP trying to fix index types
jsdt 39bbd45
remove index stuff for now
jsdt 5dc7764
qb
jsdt 0da157a
A version with a lot of different attempts at join enforcement
jsdt 1633a01
Add TableDef
jsdt 02b5b30
Create a querybuilder
jsdt 4f32ff6
Add a scan function to start queries
jsdt 072fbeb
rename scan to query
jsdt 80bc886
Add some more booleans and adds some sql tests.
jsdt eae413e
Support identities
jsdt 861c52c
fix push reducer type
jsdt e5e8e48
Exists in WIP
jsdt 3615744
Get semijoin working
jsdt a66fa3a
Get semijoin rendering working.
jsdt 6133b8c
Cleanup
jsdt 971a891
Merge branch 'master' into jsdt/ts-query-builder-2
jsdt 811e524
Fix the table name equality check
jsdt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,91 @@ | ||
| import type { U32 } from '../lib/autogen/algebraic_type_variants'; | ||
| import type { Indexes, UniqueIndex } from './indexes'; | ||
| import { | ||
| eq, | ||
| literal, | ||
| type RowExpr, | ||
| type TableNames, | ||
| type TableSchemaAsTableDef, | ||
| } from './query'; | ||
| import { schema } from './schema'; | ||
| import { table, type TableIndexes } from './table'; | ||
| import t from './type_builders'; | ||
|
|
||
| const person = table( | ||
| { | ||
| name: 'person', | ||
| indexes: [ | ||
| { | ||
| name: 'id_name_idx', | ||
| algorithm: 'btree', | ||
| columns: ['id', 'name'] as const, | ||
| }, | ||
| { | ||
| name: 'name_idx', | ||
| algorithm: 'btree', | ||
| columns: ['name'] as const, | ||
| }, | ||
| ] as const, | ||
| }, | ||
| { | ||
| id: t.u32().primaryKey(), | ||
| name: t.string(), | ||
| married: t.bool(), | ||
| id2: t.identity(), | ||
| age: t.u32(), | ||
| age2: t.u16(), | ||
| } | ||
| ); | ||
|
|
||
| const order = table( | ||
| { | ||
| name: 'order', | ||
| }, | ||
| { | ||
| order_id: t.u32().primaryKey(), | ||
| item_name: t.string(), | ||
| person_id: t.u32().index(), | ||
| } | ||
| ); | ||
|
|
||
| const spacetimedb = schema([person, order]); | ||
|
|
||
| const tableDef = { | ||
| name: person.tableName, | ||
| columns: person.rowType.row, | ||
| indexes: person.idxs, // keep the typed, literal tuples here | ||
| } as TableSchemaAsTableDef<typeof person>; | ||
|
|
||
| type PersonDef = typeof tableDef; | ||
|
|
||
| declare const row: RowExpr<PersonDef>; | ||
|
|
||
| const x: U32 = row.age.spacetimeType; | ||
|
|
||
| type SchemaTableNames = TableNames<(typeof spacetimedb)['schemaType']>; | ||
| const y: SchemaTableNames = 'person'; | ||
|
|
||
| const orderDef = { | ||
| name: order.tableName, | ||
| columns: order.rowType.row, | ||
| indexes: order.idxs, | ||
| }; | ||
|
|
||
| spacetimedb.init(ctx => { | ||
| const firstQuery = ctx.queryBuilder.query('person'); | ||
| firstQuery.semijoinTo( | ||
| ctx.queryBuilder.order, | ||
| p => p.age, | ||
| o => o.item_name | ||
| ); | ||
| const filteredQuery = ctx.queryBuilder | ||
| .query('person') | ||
| .filter(row => eq(row.age, literal(20))); | ||
|
|
||
| // Eventually this should not type check. | ||
| const _semijoin = filteredQuery.semijoinTo( | ||
| ctx.queryBuilder.order, | ||
| p => p.age, | ||
| o => o.item_name | ||
| ); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we decided on