diff --git a/dist/commands/schema.js b/dist/commands/schema.js index 7908ce1..8f98bbe 100644 --- a/dist/commands/schema.js +++ b/dist/commands/schema.js @@ -44,6 +44,7 @@ function default_1() { (0, schema_to_typedef_1.default)({ dbSchema: finaldbSchema, dst_file: out_file, + config, }); } console.log(`${chalk_1.default.bold(chalk_1.default.green(`DB Schema setup success!`))}`); diff --git a/dist/commands/typedef.js b/dist/commands/typedef.js index 460586f..dc41a00 100644 --- a/dist/commands/typedef.js +++ b/dist/commands/typedef.js @@ -25,7 +25,7 @@ function default_1() { .description("Build DB From Schema") .action((opts) => __awaiter(this, void 0, void 0, function* () { console.log(`Creating Type Definition From DB Schema ...`); - const { config, dbSchema } = yield (0, init_1.default)(); + const { config, dbSchema } = (0, init_1.default)(); const { ROOT_DIR } = (0, grab_dir_names_1.default)(); const finaldbSchema = (0, append_default_fields_to_db_schema_1.default)({ dbSchema }); if (config.typedef_file_path) { @@ -33,6 +33,7 @@ function default_1() { (0, schema_to_typedef_1.default)({ dbSchema: finaldbSchema, dst_file: out_file, + config, }); } else { diff --git a/dist/lib/sqlite/db-schema-to-typedef.d.ts b/dist/lib/sqlite/db-schema-to-typedef.d.ts index 6ec9bf8..254b9ff 100644 --- a/dist/lib/sqlite/db-schema-to-typedef.d.ts +++ b/dist/lib/sqlite/db-schema-to-typedef.d.ts @@ -1,6 +1,7 @@ -import type { NSQLITE_DatabaseSchemaType } from "../../types"; +import type { NSQLITE_DatabaseSchemaType, NSQLiteConfig } from "../../types"; type Params = { - dbSchema?: NSQLITE_DatabaseSchemaType; + dbSchema: NSQLITE_DatabaseSchemaType; + config: NSQLiteConfig; }; -export default function dbSchemaToType(params?: Params): string[] | undefined; +export default function dbSchemaToType({ config, dbSchema, }: Params): string[] | undefined; export {}; diff --git a/dist/lib/sqlite/db-schema-to-typedef.js b/dist/lib/sqlite/db-schema-to-typedef.js index 4ed5162..343c615 100644 --- a/dist/lib/sqlite/db-schema-to-typedef.js +++ b/dist/lib/sqlite/db-schema-to-typedef.js @@ -6,16 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.default = dbSchemaToType; const lodash_1 = __importDefault(require("lodash")); const db_generate_type_defs_1 = __importDefault(require("./db-generate-type-defs")); -function dbSchemaToType(params) { +function dbSchemaToType({ config, dbSchema, }) { var _a; - let datasquirelSchema = params === null || params === void 0 ? void 0 : params.dbSchema; + let datasquirelSchema = dbSchema; if (!datasquirelSchema) return; let tableNames = `export const NSQLiteTables = [\n${datasquirelSchema.tables .map((tbl) => ` "${tbl.tableName}",`) .join("\n")}\n] as const`; const dbTablesSchemas = datasquirelSchema.tables; - const defDbName = (_a = datasquirelSchema.dbName) === null || _a === void 0 ? void 0 : _a.toUpperCase().replace(/ |\-/g, "_"); + const defDbName = (_a = config.db_name) === null || _a === void 0 ? void 0 : _a.toUpperCase().replace(/ |\-/g, "_"); const defNames = []; const schemas = dbTablesSchemas .map((table) => { diff --git a/dist/lib/sqlite/schema-to-typedef.d.ts b/dist/lib/sqlite/schema-to-typedef.d.ts index c20925c..d5ec979 100644 --- a/dist/lib/sqlite/schema-to-typedef.d.ts +++ b/dist/lib/sqlite/schema-to-typedef.d.ts @@ -1,7 +1,8 @@ -import type { NSQLITE_DatabaseSchemaType } from "../../types"; +import type { NSQLITE_DatabaseSchemaType, NSQLiteConfig } from "../../types"; type Params = { dbSchema: NSQLITE_DatabaseSchemaType; dst_file: string; + config: NSQLiteConfig; }; -export default function dbSchemaToTypeDef({ dbSchema, dst_file }: Params): void; +export default function dbSchemaToTypeDef({ dbSchema, dst_file, config, }: Params): void; export {}; diff --git a/dist/lib/sqlite/schema-to-typedef.js b/dist/lib/sqlite/schema-to-typedef.js index 4e571d4..4c18636 100644 --- a/dist/lib/sqlite/schema-to-typedef.js +++ b/dist/lib/sqlite/schema-to-typedef.js @@ -7,11 +7,11 @@ exports.default = dbSchemaToTypeDef; const node_path_1 = __importDefault(require("node:path")); const node_fs_1 = require("node:fs"); const db_schema_to_typedef_1 = __importDefault(require("./db-schema-to-typedef")); -function dbSchemaToTypeDef({ dbSchema, dst_file }) { +function dbSchemaToTypeDef({ dbSchema, dst_file, config, }) { try { if (!dbSchema) throw new Error("No schema found"); - const definitions = (0, db_schema_to_typedef_1.default)({ dbSchema }); + const definitions = (0, db_schema_to_typedef_1.default)({ dbSchema, config }); const ourfileDir = node_path_1.default.dirname(dst_file); if (!(0, node_fs_1.existsSync)(ourfileDir)) { (0, node_fs_1.mkdirSync)(ourfileDir, { recursive: true }); diff --git a/package.json b/package.json index 701ab6b..bf3faa3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/nsqlite", - "version": "1.0.9", + "version": "1.0.10", "description": "SQLite manager for Node JS", "author": "Benjamin Toby", "main": "dist/index.js", diff --git a/src/commands/schema.ts b/src/commands/schema.ts index db428fb..093a69e 100644 --- a/src/commands/schema.ts +++ b/src/commands/schema.ts @@ -44,6 +44,7 @@ export default function () { dbSchemaToTypeDef({ dbSchema: finaldbSchema, dst_file: out_file, + config, }); } diff --git a/src/commands/typedef.ts b/src/commands/typedef.ts index 65dd52f..52e2fd8 100644 --- a/src/commands/typedef.ts +++ b/src/commands/typedef.ts @@ -12,7 +12,7 @@ export default function () { .action(async (opts) => { console.log(`Creating Type Definition From DB Schema ...`); - const { config, dbSchema } = await init(); + const { config, dbSchema } = init(); const { ROOT_DIR } = grabDirNames(); const finaldbSchema = appendDefaultFieldsToDbSchema({ dbSchema }); @@ -25,6 +25,7 @@ export default function () { dbSchemaToTypeDef({ dbSchema: finaldbSchema, dst_file: out_file, + config, }); } else { console.error(``); diff --git a/src/lib/sqlite/db-schema-to-typedef.ts b/src/lib/sqlite/db-schema-to-typedef.ts index 201399c..78e3f97 100644 --- a/src/lib/sqlite/db-schema-to-typedef.ts +++ b/src/lib/sqlite/db-schema-to-typedef.ts @@ -1,13 +1,17 @@ import _ from "lodash"; -import type { NSQLITE_DatabaseSchemaType } from "../../types"; +import type { NSQLITE_DatabaseSchemaType, NSQLiteConfig } from "../../types"; import generateTypeDefinition from "./db-generate-type-defs"; type Params = { - dbSchema?: NSQLITE_DatabaseSchemaType; + dbSchema: NSQLITE_DatabaseSchemaType; + config: NSQLiteConfig; }; -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 +21,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[] = []; diff --git a/src/lib/sqlite/schema-to-typedef.ts b/src/lib/sqlite/schema-to-typedef.ts index c52caf0..5079719 100644 --- a/src/lib/sqlite/schema-to-typedef.ts +++ b/src/lib/sqlite/schema-to-typedef.ts @@ -1,18 +1,23 @@ import path from "node:path"; import { existsSync, mkdirSync, writeFileSync } from "node:fs"; -import type { NSQLITE_DatabaseSchemaType } from "../../types"; +import type { NSQLITE_DatabaseSchemaType, NSQLiteConfig } from "../../types"; import dbSchemaToType from "./db-schema-to-typedef"; type Params = { dbSchema: NSQLITE_DatabaseSchemaType; dst_file: string; + config: NSQLiteConfig; }; -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);