mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 支持mysql
This commit is contained in:
@@ -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')`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user