Updates
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user