perf: 支持mysql

This commit is contained in:
xiaojunnuo
2024-12-09 17:47:01 +08:00
parent 228fdf0a0d
commit 7cde1fdc4a
27 changed files with 511 additions and 11 deletions
@@ -2,6 +2,7 @@ import { SqliteAdapter } from './sqlite.js';
import { PostgresqlAdapter } from './postgresql.js';
import { Config, Init, Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { SqlAdapter } from './d.js';
import { MysqlAdapter } from './mysql.js';
@Provide()
@Scope(ScopeEnum.Singleton)
@@ -16,8 +17,10 @@ export class DbAdapter implements SqlAdapter {
this.adapter = new SqliteAdapter();
} else if (this.isPostgresql()) {
this.adapter = new PostgresqlAdapter();
} else if (this.isMysql()) {
this.adapter = new MysqlAdapter();
} else {
throw new Error(`dbType ${this.dbType} not support`);
throw new Error(`dbType ${this.dbType} not support 请实现Adapter`);
}
}
@@ -27,6 +30,9 @@ export class DbAdapter implements SqlAdapter {
isPostgresql() {
return this.dbType === 'postgres';
}
isMysql() {
return this.dbType === 'mysql' || this.dbType === 'mariadb';
}
date(columnName: string) {
return this.adapter.date(columnName);
@@ -0,0 +1,7 @@
import { SqlAdapter } from './d.js';
export class MysqlAdapter implements SqlAdapter {
date(columnName: string) {
return `DATE_FORMAT(${columnName}, '%Y-%m-%d')`;
}
}