Skip to content

Commit

Permalink
fix: fix custom sql extension
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Apr 10, 2024
1 parent 8652c9d commit cc83190
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/dal-runtime/src/SqlMapLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SqlMapLoader {
load(): TableSqlMap {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const customSqlMap: Record<string, SqlMap> = require(this.sqlMapPath);
const { default: customSqlMap }: { default: Record<string, SqlMap> } = require(this.sqlMapPath);
const baseSqlMapGenerator = new BaseSqlMapGenerator(this.tableModel, this.logger);
const baseSqlMap = baseSqlMapGenerator.load();
const sqlMap = {
Expand Down
17 changes: 17 additions & 0 deletions core/dal-runtime/test/TableSqlMap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import assert from 'node:assert';
import { TableModel } from '@eggjs/dal-decorator';
import { Foo } from './fixtures/modules/dal/Foo';
import { SqlMapLoader } from '../src/SqlMapLoader';
import path from 'node:path';

describe('test/TableSqlMap.test.ts', () => {
it('custom sql should work', () => {
// const generator = new SqlGenerator();
const fooModel = TableModel.build(Foo);
// const sql = generator.generate(fooModel);
const sqlMapLoader = new SqlMapLoader(fooModel, path.join(__dirname, 'fixtures/modules/dal'), console);
const tableSqlMap = sqlMapLoader.load();
const sql = tableSqlMap.generate('findAll', {}, 'UTC');
assert.equal(sql, 'SELECT `id`,`name`,`col1`,`bit_column`,`bool_column`,`tiny_int_column`,`small_int_column`,`medium_int_column`,`int_column`,`big_int_column`,`decimal_column`,`float_column`,`double_column`,`date_column`,`date_time_column`,`timestamp_column`,`time_column`,`year_column`,`var_char_column`,`binary_column`,`var_binary_column`,`tiny_blob_column`,`tiny_text_column`,`blob_column`,`text_column`,`medium_blob_column`,`long_blob_column`,`medium_text_column`,`long_text_column`,`enum_column`,`set_column`,`geometry_column`,`point_column`,`line_string_column`,`polygon_column`,`multipoint_column`,`multi_line_string_column`,`multi_polygon_column`,`geometry_collection_column`,`json_column` from egg_foo;');
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { SqlMap } from '@eggjs/dal-decorator';
import { SqlMap, SqlType } from '@eggjs/dal-decorator';

export default {

findAll: {
type: SqlType.SELECT,
sql: 'SELECT {{ allColumns}} from egg_foo;'
},
} as Record<string, SqlMap>;

0 comments on commit cc83190

Please sign in to comment.