Skip to content
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

add TypeScript benchmarks. #1314

Open
wants to merge 20 commits into
base: v0.28
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,22 @@ jobs:

- name: Type-check JSDocs code blocks
run: npm run test:jsdocs

typescript-benchmarks:
name: TypeScript Benchmarks
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run benchmarks
run: npm run bench:ts
196 changes: 191 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"scripts": {
"clean": "rm -rf dist & rm -rf test/node/dist & rm -rf test/browser/bundle.js & rm -rf helpers",
"bench:ts": "npm run build && cd ./test/ts-benchmarks && tsx ./index.ts",
"test": "npm run build && npm run test:node:build && npm run test:node:run && npm run test:typings && npm run test:esmimports && npm run test:exports",
"test:node:build": "tsc -p test/node",
"test:node": "npm run build && npm run test:node:build && npm run test:node:run",
Expand Down Expand Up @@ -82,6 +83,7 @@
],
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.0",
"@ark/attest": "^0.36.0",
"@types/better-sqlite3": "^7.6.11",
"@types/chai": "^4.3.17",
"@types/chai-as-promised": "^7.1.8",
Expand Down
31 changes: 15 additions & 16 deletions src/parser/select-from-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ 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>, {}>
> = 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
: TE extends ReadonlyArray<infer T>
? SelectQueryBuilder<From<DB, T>, FromTables<DB, TB, T>, {}>
: SelectQueryBuilder<From<DB, TE>, FromTables<DB, TB, TE>, {}>
1 change: 1 addition & 0 deletions test/ts-benchmarks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './selectFrom.bench.js'
Loading
Loading