Updates
This commit is contained in:
Vendored
+1
@@ -30,6 +30,7 @@ export default function () {
|
||||
dbSchemaToTypeDef({
|
||||
dbSchema: finaldbSchema,
|
||||
dst_file: out_file,
|
||||
config,
|
||||
});
|
||||
}
|
||||
console.log(`${chalk.bold(chalk.green(`DB Schema setup success!`))}`);
|
||||
|
||||
Vendored
+1
@@ -18,6 +18,7 @@ export default function () {
|
||||
dbSchemaToTypeDef({
|
||||
dbSchema: finaldbSchema,
|
||||
dst_file: out_file,
|
||||
config,
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
import type { BUN_SQLITE_DatabaseSchemaType } from "../../types";
|
||||
import type { BUN_SQLITE_DatabaseSchemaType, BunSQLiteConfig } from "../../types";
|
||||
type Params = {
|
||||
dbSchema?: BUN_SQLITE_DatabaseSchemaType;
|
||||
dbSchema: BUN_SQLITE_DatabaseSchemaType;
|
||||
config: BunSQLiteConfig;
|
||||
};
|
||||
export default function dbSchemaToType(params?: Params): string[] | undefined;
|
||||
export default function dbSchemaToType({ config, dbSchema, }: Params): string[] | undefined;
|
||||
export {};
|
||||
|
||||
+3
-5
@@ -1,16 +1,14 @@
|
||||
import _ from "lodash";
|
||||
import generateTypeDefinition from "./db-generate-type-defs";
|
||||
export default function dbSchemaToType(params) {
|
||||
let datasquirelSchema = params?.dbSchema;
|
||||
export default function dbSchemaToType({ config, dbSchema, }) {
|
||||
let datasquirelSchema = dbSchema;
|
||||
if (!datasquirelSchema)
|
||||
return;
|
||||
let tableNames = `export const BunSQLiteTables = [\n${datasquirelSchema.tables
|
||||
.map((tbl) => ` "${tbl.tableName}",`)
|
||||
.join("\n")}\n] as const`;
|
||||
const dbTablesSchemas = datasquirelSchema.tables;
|
||||
const defDbName = datasquirelSchema.dbName
|
||||
?.toUpperCase()
|
||||
.replace(/ |\-/g, "_");
|
||||
const defDbName = config.db_name?.toUpperCase().replace(/ |\-/g, "_");
|
||||
const defNames = [];
|
||||
const schemas = dbTablesSchemas
|
||||
.map((table) => {
|
||||
|
||||
+3
-2
@@ -1,7 +1,8 @@
|
||||
import type { BUN_SQLITE_DatabaseSchemaType } from "../../types";
|
||||
import type { BUN_SQLITE_DatabaseSchemaType, BunSQLiteConfig } from "../../types";
|
||||
type Params = {
|
||||
dbSchema: BUN_SQLITE_DatabaseSchemaType;
|
||||
dst_file: string;
|
||||
config: BunSQLiteConfig;
|
||||
};
|
||||
export default function dbSchemaToTypeDef({ dbSchema, dst_file }: Params): void;
|
||||
export default function dbSchemaToTypeDef({ dbSchema, dst_file, config, }: Params): void;
|
||||
export {};
|
||||
|
||||
Vendored
+2
-2
@@ -1,11 +1,11 @@
|
||||
import path from "node:path";
|
||||
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
||||
import dbSchemaToType from "./db-schema-to-typedef";
|
||||
export default function dbSchemaToTypeDef({ dbSchema, dst_file }) {
|
||||
export default function dbSchemaToTypeDef({ dbSchema, dst_file, config, }) {
|
||||
try {
|
||||
if (!dbSchema)
|
||||
throw new Error("No schema found");
|
||||
const definitions = dbSchemaToType({ dbSchema });
|
||||
const definitions = dbSchemaToType({ dbSchema, config });
|
||||
const ourfileDir = path.dirname(dst_file);
|
||||
if (!existsSync(ourfileDir)) {
|
||||
mkdirSync(ourfileDir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user