Updates
This commit is contained in:
parent
42ee8eaaa1
commit
bf1c364e36
1
dist/commands/schema.js
vendored
1
dist/commands/schema.js
vendored
@ -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!`))}`);
|
||||
|
||||
3
dist/commands/typedef.js
vendored
3
dist/commands/typedef.js
vendored
@ -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 {
|
||||
|
||||
7
dist/lib/sqlite/db-schema-to-typedef.d.ts
vendored
7
dist/lib/sqlite/db-schema-to-typedef.d.ts
vendored
@ -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 {};
|
||||
|
||||
6
dist/lib/sqlite/db-schema-to-typedef.js
vendored
6
dist/lib/sqlite/db-schema-to-typedef.js
vendored
@ -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) => {
|
||||
|
||||
5
dist/lib/sqlite/schema-to-typedef.d.ts
vendored
5
dist/lib/sqlite/schema-to-typedef.d.ts
vendored
@ -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 {};
|
||||
|
||||
4
dist/lib/sqlite/schema-to-typedef.js
vendored
4
dist/lib/sqlite/schema-to-typedef.js
vendored
@ -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 });
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -44,6 +44,7 @@ export default function () {
|
||||
dbSchemaToTypeDef({
|
||||
dbSchema: finaldbSchema,
|
||||
dst_file: out_file,
|
||||
config,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -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(``);
|
||||
|
||||
@ -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[] = [];
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user