This commit is contained in:
2026-03-11 05:39:08 +01:00
parent 42ee8eaaa1
commit bf1c364e36
11 changed files with 36 additions and 23 deletions
+1
View File
@@ -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!`))}`);
+2 -1
View File
@@ -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 {
+4 -3
View File
@@ -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 {};
+3 -3
View File
@@ -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) => {
+3 -2
View File
@@ -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 {};
+2 -2
View File
@@ -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 });