Skip to content

Commit 69c9098

Browse files
authored
fix: resolve circular dependency between api and db by moving Sql type to types package (#12)
1 parent 32a2ba9 commit 69c9098

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

api/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { respond } from '@01edu/api/response'
33
import type { RequestContext } from '@01edu/types/context'
44
import { route } from '@01edu/api/router'
55
import { ARR, OBJ, optional, STR } from '@01edu/api/validator'
6-
import type { Sql } from '@01edu/db'
6+
import type { Sql } from '@01edu/types/db'
77

88
/**
99
* Authorizes access to developer routes.

api/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type {
2222
} from '@01edu/types/router'
2323
import type { Log } from './log.ts'
2424
import { respond, ResponseError } from './response.ts'
25-
import type { Sql } from '@01edu/db'
25+
import type { Sql } from '@01edu/types/db'
2626
import { createSqlDevRoute } from './dev.ts'
2727
import { createDocRoute } from './doc.ts'
2828

db/mod.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
type RestBindParameters,
1515
} from '@db/sqlite'
1616
import type { Expand, MatchKeys, UnionToIntersection } from '@01edu/types'
17+
import type { Sql } from '@01edu/types/db'
1718
import { respond } from '@01edu/api/response'
1819
import { APP_ENV, ENV } from '@01edu/api/env'
1920

@@ -403,20 +404,6 @@ export const createTable = <N extends string, P extends TableProperties>(
403404
}
404405
}
405406

406-
/**
407-
* Type definition for the `sql` template tag function.
408-
* It allows executing SQL queries with parameter binding and retrieving results in various formats.
409-
*/
410-
export type Sql = <
411-
T extends { [k in string]: unknown } | undefined,
412-
P extends BindValue | BindParameters | undefined,
413-
>(sqlArr: TemplateStringsArray, ...vars: unknown[]) => {
414-
get: (params?: P) => T | undefined
415-
all: (params?: P) => T[]
416-
run: (params?: P) => void
417-
value: (params?: P) => T[keyof T][] | undefined
418-
}
419-
420407
/**
421408
* A template literal tag for executing arbitrary SQL queries.
422409
*

deno.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

types/db.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { BindParameters, BindValue } from '@db/sqlite'
2+
3+
/**
4+
* Type definition for the `sql` template tag function.
5+
* It allows executing SQL queries with parameter binding and retrieving results in various formats.
6+
*/
7+
export type Sql = <
8+
T extends { [k in string]: unknown } | undefined,
9+
P extends BindValue | BindParameters | undefined,
10+
>(sqlArr: TemplateStringsArray, ...vars: unknown[]) => {
11+
get: (params?: P) => T | undefined
12+
all: (params?: P) => T[]
13+
run: (params?: P) => void
14+
value: (params?: P) => T[keyof T][] | undefined
15+
}

types/deno.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
2-
"imports": {},
2+
"imports": {
3+
"@db/sqlite": "jsr:@db/sqlite@^0.13.0"
4+
},
35
"name": "@01edu/types",
4-
"version": "0.1.3",
6+
"version": "0.1.4",
57
"license": "MIT",
68
"exports": {
79
".": "./mod.d.ts",
810
"./context": "./context.d.ts",
11+
"./db": "./db.d.ts",
912
"./router": "./router.d.ts",
1013
"./validator": "./validator.d.ts"
1114
}

0 commit comments

Comments
 (0)