This commit is contained in:
2026-03-11 05:40:37 +01:00
parent 406759306b
commit e7ee76f572
11 changed files with 40 additions and 23 deletions
+12 -7
View File
@@ -1,13 +1,20 @@
import _ from "lodash";
import type { BUN_SQLITE_DatabaseSchemaType } from "../../types";
import type {
BUN_SQLITE_DatabaseSchemaType,
BunSQLiteConfig,
} from "../../types";
import generateTypeDefinition from "./db-generate-type-defs";
type Params = {
dbSchema?: BUN_SQLITE_DatabaseSchemaType;
dbSchema: BUN_SQLITE_DatabaseSchemaType;
config: BunSQLiteConfig;
};
export default function dbSchemaToType(params?: Params): string[] | undefined {
let datasquirelSchema = params?.dbSchema;
export default function dbSchemaToType({
config,
dbSchema,
}: Params): string[] | undefined {
let datasquirelSchema = dbSchema;
if (!datasquirelSchema) return;
@@ -17,9 +24,7 @@ export default function dbSchemaToType(params?: Params): string[] | undefined {
const dbTablesSchemas = datasquirelSchema.tables;
const defDbName = datasquirelSchema.dbName
?.toUpperCase()
.replace(/ |\-/g, "_");
const defDbName = config.db_name?.toUpperCase().replace(/ |\-/g, "_");
const defNames: string[] = [];
+11 -3
View File
@@ -1,18 +1,26 @@
import path from "node:path";
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
import type { BUN_SQLITE_DatabaseSchemaType } from "../../types";
import type {
BUN_SQLITE_DatabaseSchemaType,
BunSQLiteConfig,
} from "../../types";
import dbSchemaToType from "./db-schema-to-typedef";
type Params = {
dbSchema: BUN_SQLITE_DatabaseSchemaType;
dst_file: string;
config: BunSQLiteConfig;
};
export default function dbSchemaToTypeDef({ dbSchema, dst_file }: Params) {
export default function dbSchemaToTypeDef({
dbSchema,
dst_file,
config,
}: Params) {
try {
if (!dbSchema) throw new Error("No schema found");
const definitions = dbSchemaToType({ dbSchema });
const definitions = dbSchemaToType({ dbSchema, config });
const ourfileDir = path.dirname(dst_file);