Skip to content

Commit

Permalink
fix: fix dev config
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrxyy committed Sep 5, 2024
1 parent edbac36 commit cd42965
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 34 deletions.
4 changes: 3 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"webpack": false,
"deleteOutDir": true,
"assets": [
"**/*.md"
],
"builder": {
"type": "swc"
"type": "swc",
"options": {}
},
"watchAssets": true
}
Expand Down
24 changes: 17 additions & 7 deletions src/models/Querys/index.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { InjectModel } from '@nestjs/sequelize';
import { DB } from './DB.model';
import knex from 'knex';
import { generateDbdiagramDsl } from 'src/utils/knex/DB2DBML';
import { each, get, map, mapValues, pick } from 'lodash';
import { get, map, mapValues, pick } from 'lodash';
import { Knex } from 'knex';
import { executeSQLWithDisabledForeignKeys } from 'src/utils/knex/executeSQLWithDisabledForeignKeys';
import exportDsl from 'src/utils/knex/export-dsl';
Expand All @@ -18,7 +18,6 @@ import SequelizeAuto, { TableData } from 'sequelize-auto-model';
import { importer } from '@dbml/core';
import schemaInspector from 'knex-schema-inspector';
import { dbDrivers } from './DBTypes';
import { DataTypes } from 'sequelize';

function pureCode(raw: string): string {
const codeRegex = /```.*\n([\s\S]*?)\n```/;
Expand Down Expand Up @@ -82,6 +81,12 @@ export class QueriesService implements OnModuleInit {
}) => {
if (type === 'sql') {
const sqlArr = content.split(/;\n/);
if (sqlArr.length) {
sqlArr[sqlArr.length - 1] = sqlArr[sqlArr.length - 1].replace(
/;(\n)*?$/g,
'',
);
}
const params = [];
const templateSqlArr = [];
for (let i = 0; i < sqlArr.length; i++) {
Expand Down Expand Up @@ -355,9 +360,9 @@ export class QueriesService implements OnModuleInit {
const auto = new SequelizeAuto(sequelizeInstance, null, null, options);
let tableData = await auto.build(false);
tableData = auto.relate(tableData);
// auto.generateFn(tableData)(); without relation
auto.getCreateModelsFn(tableData)();
// this.setupAssociations(sequelizeInstance.models, tableData.relations);
auto.generateModelsFn(tableData)(); //without relation
// auto.getCreateModelsFn(tableData)();
this.setupAssociations(sequelizeInstance.models, tableData.relations);
return sequelizeInstance;
}

Expand Down Expand Up @@ -402,10 +407,15 @@ export class QueriesService implements OnModuleInit {
attributes,
options,
) || '';
return sql;
switch (client) {
case 'oracle':
//TODO dbml 当前不支持 ql/sql
return sql.slice(25, -73) + ';';
default:
return sql;
}
});
try {
console.log(tableSql, 'tableSql');
const data = importer.import(tableSql.join('\n'), client as any);
sequelizeInstance.close();
return {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/knex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ export class KnexContainer {
!KnexContainer.oracledbInit
) {
try {
//https://medium.com/oracledevs/how-to-install-node-oracledb-5-5-and-oracle-database-on-apple-m1-m2-silicon-941fccda692f
oracledb.initOracleClient({
libDir:
process.env['LD_LIBRARY_PATH'] ||
process.env.HOME + '/Downloads/instantclient_19_8',
});
console.log('启用oracle厚模式');
KnexContainer.oracledbInit = true;
} catch (e) {
console.log('无法使用oracle厚模式');
console.log(e, '无法使用oracle厚模式');
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"paths": {
"@dbml/core": ["../packages/dbml/packages/dbml-core"],
"sequelize-auto-model": ["./packages/sequelize-auto-model"]
}
},
"include": ["src/**/*.ts", "src/**/*.md"]
}
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"paths": {
"@dbml/core": ["./node_modules/dbml-core"],
Expand Down
25 changes: 1 addition & 24 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"paths": {
"@dbml/core": ["../packages/dbml/packages/dbml-core"],
"sequelize-auto-model": ["./packages/sequelize-auto-model"]
}
},
"include": ["src/**/*.ts", "src/**/*.md"]
"extends": ["./tsconfig.base.json", "./tsconfig.dev.json"]
}

0 comments on commit cd42965

Please sign in to comment.