forked from Yedidyar/remult-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Yedidyar#6 from Yedidyar/4-implement-foreign-keys-…
…such-as-it-will-be-robust feat: add getForeignKeys & extract commands & add types
- Loading branch information
Showing
4 changed files
with
232 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ForeignKey } from "./postgres/commands.js"; | ||
import { toCamelCase, toPascalCase } from "./utils/case.js"; | ||
|
||
export class DbTable { | ||
schema: string; | ||
dbName: string; | ||
key: string; | ||
className: string; | ||
foreignKeys: { | ||
columnName: string; | ||
foreignClassName: string; | ||
}[]; | ||
|
||
constructor(dbName: string, schema: string, foreignKeys: ForeignKey[]) { | ||
this.schema = schema; | ||
this.dbName = dbName; | ||
|
||
this.foreignKeys = foreignKeys.map( | ||
({ foreign_table_name, column_name: columnName }) => ({ | ||
columnName, | ||
foreignClassName: toPascalCase(foreign_table_name), | ||
}) | ||
); | ||
this.className = toPascalCase(dbName); | ||
|
||
this.key = toCamelCase(this.className) + "s"; | ||
|
||
// TODO: kinda hacky provide a custom mapping? | ||
if (this.key.endsWith("ys")) { | ||
this.key = this.key.slice(0, -2) + "ies"; | ||
} | ||
} | ||
} |
Oops, something went wrong.