fix(db): correct dialect import paths and extend bip-users-dao type
- Fix dialect files to use relative paths instead of @types alias - Add 'postgresql' to BIPUsersDAO dbType union Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
* Creates the appropriate SqlDialect implementation based on database type.
|
||||
*/
|
||||
|
||||
import type { DatabaseType } from '@types/database.types'
|
||||
import type { SqlDialect } from '@types/sql-dialect.types'
|
||||
import type { DatabaseType } from '../../../types/database.types'
|
||||
import type { SqlDialect } from '../../../types/sql-dialect.types'
|
||||
|
||||
import { MySqlDialect } from './mysql-dialect'
|
||||
import { PostgreSqlDialect } from './postgresql-dialect'
|
||||
@@ -14,7 +14,7 @@ import { SqlServerDialect } from './sqlserver-dialect'
|
||||
export { MySqlDialect } from './mysql-dialect'
|
||||
export { PostgreSqlDialect } from './postgresql-dialect'
|
||||
export { SqlServerDialect } from './sqlserver-dialect'
|
||||
export type { SqlDialect } from '@types/sql-dialect.types'
|
||||
export type { SqlDialect } from '../../../types/sql-dialect.types'
|
||||
|
||||
export function createDialect(type: DatabaseType): SqlDialect {
|
||||
switch (type) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* - LIMIT/OFFSET pagination
|
||||
*/
|
||||
|
||||
import type { SqlDialect } from '@types/sql-dialect.types'
|
||||
import type { SqlDialect } from '../../../types/sql-dialect.types'
|
||||
|
||||
export class MySqlDialect implements SqlDialect {
|
||||
readonly dbType = 'mysql' as const
|
||||
@@ -41,9 +41,7 @@ export class MySqlDialect implements SqlDialect {
|
||||
const placeholders = allColumns.map(() => '?').join(', ')
|
||||
|
||||
const nonKeyColumns = allColumns.filter((col) => !keyColumns.includes(col))
|
||||
const updateClause = nonKeyColumns
|
||||
.map((col) => `${col} = VALUES(${col})`)
|
||||
.join(', ')
|
||||
const updateClause = nonKeyColumns.map((col) => `${col} = VALUES(${col})`).join(', ')
|
||||
|
||||
const sql = `INSERT INTO ${table} (${columns}) VALUES (${placeholders}) ON DUPLICATE KEY UPDATE ${updateClause}`
|
||||
|
||||
@@ -53,12 +51,10 @@ export class MySqlDialect implements SqlDialect {
|
||||
}
|
||||
}
|
||||
|
||||
paginate(params: {
|
||||
paginate(params: { sql: string; limit: number; offset?: number; paramIndex: number }): {
|
||||
sql: string
|
||||
limit: number
|
||||
offset?: number
|
||||
paramIndex: number
|
||||
}): { sql: string; nextParamIndex: number } {
|
||||
nextParamIndex: number
|
||||
} {
|
||||
const { sql, limit, offset, paramIndex } = params
|
||||
|
||||
return {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* - LIMIT/OFFSET pagination
|
||||
*/
|
||||
|
||||
import type { SqlDialect } from '@types/sql-dialect.types'
|
||||
import type { SqlDialect } from '../../../types/sql-dialect.types'
|
||||
|
||||
export class PostgreSqlDialect implements SqlDialect {
|
||||
readonly dbType = 'postgresql' as const
|
||||
@@ -38,16 +38,12 @@ export class PostgreSqlDialect implements SqlDialect {
|
||||
const { table, keyColumns, allColumns, startParamIndex } = params
|
||||
|
||||
const columns = allColumns.join(', ')
|
||||
const placeholders = allColumns
|
||||
.map((_, i) => `$${startParamIndex + i + 1}`)
|
||||
.join(', ')
|
||||
const placeholders = allColumns.map((_, i) => `$${startParamIndex + i + 1}`).join(', ')
|
||||
|
||||
const conflictKeys = keyColumns.map((col) => `"${col}"`).join(', ')
|
||||
|
||||
const nonKeyColumns = allColumns.filter((col) => !keyColumns.includes(col))
|
||||
const updateSet = nonKeyColumns
|
||||
.map((col) => `"${col}" = EXCLUDED."${col}"`)
|
||||
.join(', ')
|
||||
const updateSet = nonKeyColumns.map((col) => `"${col}" = EXCLUDED."${col}"`).join(', ')
|
||||
|
||||
const sql = [
|
||||
`INSERT INTO ${table} (${columns}) VALUES (${placeholders})`,
|
||||
@@ -61,12 +57,10 @@ export class PostgreSqlDialect implements SqlDialect {
|
||||
}
|
||||
}
|
||||
|
||||
paginate(params: {
|
||||
paginate(params: { sql: string; limit: number; offset?: number; paramIndex: number }): {
|
||||
sql: string
|
||||
limit: number
|
||||
offset?: number
|
||||
paramIndex: number
|
||||
}): { sql: string; nextParamIndex: number } {
|
||||
nextParamIndex: number
|
||||
} {
|
||||
const { sql, limit, offset, paramIndex } = params
|
||||
|
||||
return {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* - OFFSET/FETCH pagination
|
||||
*/
|
||||
|
||||
import type { SqlDialect } from '@types/sql-dialect.types'
|
||||
import type { SqlDialect } from '../../../types/sql-dialect.types'
|
||||
|
||||
export class SqlServerDialect implements SqlDialect {
|
||||
readonly dbType = 'sqlserver' as const
|
||||
@@ -37,19 +37,13 @@ export class SqlServerDialect implements SqlDialect {
|
||||
}): { sql: string; nextParamIndex: number } {
|
||||
const { table, keyColumns, allColumns, startParamIndex } = params
|
||||
|
||||
const valueParams = allColumns
|
||||
.map((_, i) => `@p${startParamIndex + i}`)
|
||||
.join(', ')
|
||||
const valueParams = allColumns.map((_, i) => `@p${startParamIndex + i}`).join(', ')
|
||||
const sourceColumns = allColumns.join(', ')
|
||||
|
||||
const joinCondition = keyColumns
|
||||
.map((col) => `target.${col} = source.${col}`)
|
||||
.join(' AND ')
|
||||
const joinCondition = keyColumns.map((col) => `target.${col} = source.${col}`).join(' AND ')
|
||||
|
||||
const nonKeyColumns = allColumns.filter((col) => !keyColumns.includes(col))
|
||||
const updateSet = nonKeyColumns
|
||||
.map((col) => `target.${col} = source.${col}`)
|
||||
.join(', ')
|
||||
const updateSet = nonKeyColumns.map((col) => `target.${col} = source.${col}`).join(', ')
|
||||
|
||||
const insertColumns = allColumns.join(', ')
|
||||
const insertValues = allColumns.map((col) => `source.${col}`).join(', ')
|
||||
@@ -68,12 +62,10 @@ export class SqlServerDialect implements SqlDialect {
|
||||
}
|
||||
}
|
||||
|
||||
paginate(params: {
|
||||
paginate(params: { sql: string; limit: number; offset?: number; paramIndex: number }): {
|
||||
sql: string
|
||||
limit: number
|
||||
offset?: number
|
||||
paramIndex: number
|
||||
}): { sql: string; nextParamIndex: number } {
|
||||
nextParamIndex: number
|
||||
} {
|
||||
const { sql, limit, offset, paramIndex } = params
|
||||
|
||||
if (offset !== undefined) {
|
||||
|
||||
@@ -46,7 +46,7 @@ export const BIP_USERS_CONFIG = {
|
||||
export class BIPUsersDAO {
|
||||
private mysqlService: MySqlService | null = null
|
||||
private sqlServerService: SqlServerService | null = null
|
||||
private dbType: 'mysql' | 'sqlserver' = 'mysql'
|
||||
private dbType: 'mysql' | 'sqlserver' | 'postgresql' = 'mysql'
|
||||
private configManager: ConfigManager
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user