Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion api/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { respond } from '@01edu/api/response'
import type { RequestContext } from '@01edu/types/context'
import { route } from '@01edu/api/router'
import { ARR, OBJ, optional, STR } from '@01edu/api/validator'
import type { Sql } from '@01edu/db'
import type { Sql } from '@01edu/types/db'

/**
* Authorizes access to developer routes.
Expand Down
2 changes: 1 addition & 1 deletion api/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type {
} from '@01edu/types/router'
import type { Log } from './log.ts'
import { respond, ResponseError } from './response.ts'
import type { Sql } from '@01edu/db'
import type { Sql } from '@01edu/types/db'
import { createSqlDevRoute } from './dev.ts'
import { createDocRoute } from './doc.ts'

Expand Down
15 changes: 1 addition & 14 deletions db/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
type RestBindParameters,
} from '@db/sqlite'
import type { Expand, MatchKeys, UnionToIntersection } from '@01edu/types'
import type { Sql } from '@01edu/types/db'
import { respond } from '@01edu/api/response'
import { APP_ENV, ENV } from '@01edu/api/env'

Expand Down Expand Up @@ -403,20 +404,6 @@ export const createTable = <N extends string, P extends TableProperties>(
}
}

/**
* Type definition for the `sql` template tag function.
* It allows executing SQL queries with parameter binding and retrieving results in various formats.
*/
export type Sql = <
T extends { [k in string]: unknown } | undefined,
P extends BindValue | BindParameters | undefined,
>(sqlArr: TemplateStringsArray, ...vars: unknown[]) => {
get: (params?: P) => T | undefined
all: (params?: P) => T[]
run: (params?: P) => void
value: (params?: P) => T[keyof T][] | undefined
}

/**
* A template literal tag for executing arbitrary SQL queries.
*
Expand Down
5 changes: 5 additions & 0 deletions deno.lock

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

15 changes: 15 additions & 0 deletions types/db.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { BindParameters, BindValue } from '@db/sqlite'

/**
* Type definition for the `sql` template tag function.
* It allows executing SQL queries with parameter binding and retrieving results in various formats.
*/
export type Sql = <
T extends { [k in string]: unknown } | undefined,
P extends BindValue | BindParameters | undefined,
>(sqlArr: TemplateStringsArray, ...vars: unknown[]) => {
get: (params?: P) => T | undefined
all: (params?: P) => T[]
run: (params?: P) => void
value: (params?: P) => T[keyof T][] | undefined
}
7 changes: 5 additions & 2 deletions types/deno.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"imports": {},
"imports": {
"@db/sqlite": "jsr:@db/sqlite@^0.13.0"
},
"name": "@01edu/types",
"version": "0.1.3",
"version": "0.1.4",
"license": "MIT",
"exports": {
".": "./mod.d.ts",
"./context": "./context.d.ts",
"./db": "./db.d.ts",
"./router": "./router.d.ts",
"./validator": "./validator.d.ts"
}
Expand Down
Loading