Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 26, 2023
1 parent bb71090 commit f51cb79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ type RemoveFirstParam<T> = T extends (first: any, ...rest: infer P) => infer R ?
export interface Relation {
type: "REL";
table: keyof Tables;
default?: string;
nullable?: boolean;
unique?: boolean;
}
export interface Column {
type: DataType;
Expand Down
17 changes: 6 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,20 @@ export class BunORM {
tables;
db;
createTable = (table, opts) => (typeof this.db.run(`CREATE TABLE IF NOT EXISTS ${table} ('id' INTEGER PRIMARY KEY AUTOINCREMENT,${Object.entries(opts.columns)
.filter(([_, opts]) => opts.type !== "REL")
.map(([col, opts]) => [
`'${col}'`,
opts.type === "JSON" ? "TEXT" : opts.type,
opts.type === "JSON"
? "TEXT"
: opts.type === "REL"
? "INTEGER"
: opts.type,
opts.default && `DEFAULT ${opts.default}`,
opts.unique && "UNIQUE",
!opts.nullable && "NOT NULL",
]
.filter((x) => !!x)
.join(" "))
.join()}${Object.entries(opts.columns).filter(([_, opts]) => opts.type === "REL").length
? "," +
Object.entries(opts.columns)
.filter(([_, opts]) => opts.type === "REL")
.map(([col, opts]) => [`'${col}' INTEGER`, !opts.nullable && "NOT NULL"]
.filter((x) => !!x)
.join(" "))
.join()
: ""},'updatedAt' DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,'createdAt' DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL${Object.entries(opts.columns).filter(([_, opts]) => opts.type === "REL").length
.join()},'updatedAt' DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,'createdAt' DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL${Object.entries(opts.columns).filter(([_, opts]) => opts.type === "REL").length
? "," +
Object.entries(opts.columns)
.filter(([_, opts]) => opts.type === "REL")
Expand Down

0 comments on commit f51cb79

Please sign in to comment.