Skip to content

Commit

Permalink
updated the bg database template: added numeric type parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Oct 23, 2024
1 parent ace1525 commit 459f3bc
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
100 changes: 100 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"git": ">=2.x.x"
},
"optionalDependencies": {
"@types/pg": "^8.11.10",
"del": "^6.1.1",
"fancy-log": "^2.0.0",
"git-commit-info": "^2.0.2",
Expand Down
16 changes: 15 additions & 1 deletion templates/pg
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// system file, please don't modify it

import * as pg from "pg"
import * as orm from "@ghom/orm"
import * as logger from "./logger.ts"
import env from "./env.ts"
import path from "path"

setTypeParsers(pg)

const client = new orm.ORM({
location: path.join(process.cwd(), "dist", "tables"),
database: {
Expand All @@ -24,4 +27,15 @@ const client = new orm.ORM({

export * from "@ghom/orm"

export default client
export default client

function setTypeParsers({ types }: typeof pg) {
const int = (value: string) => parseInt(value)
const float = (value: string) => parseFloat(value)

types.setTypeParser(types.builtins.INT2, int)
types.setTypeParser(types.builtins.INT4, int)
types.setTypeParser(types.builtins.INT8, int)
types.setTypeParser(types.builtins.FLOAT4, float)
types.setTypeParser(types.builtins.FLOAT8, float)
}

0 comments on commit 459f3bc

Please sign in to comment.