Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mysql to BasicDatabaseClient #1861

Merged
merged 8 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/studio/src/lib/db/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export interface IDbConnectionDatabase {
connecting: boolean,
}

export class DBConnection {
export class DBConnection implements DatabaseClient {
azmy60 marked this conversation as resolved.
Show resolved Hide resolved
connectionType = this.server.config.client
constructor (private server: IDbConnectionServer, private database: IDbConnectionDatabase) {}
supportedFeatures = supportedFeatures.bind(null, this.server, this.database)
Expand Down Expand Up @@ -236,6 +236,8 @@ export class DBConnection {
duplicateTable = bindAsync.bind(null, 'duplicateTable', this.server, this.database)
duplicateTableSql = bind.bind(null, 'duplicateTableSql', this.server, this.database)

wrapIdentifier = wrap.bind(null, this.database)

async currentDatabase() {
return this.database.database
}
Expand Down
8 changes: 6 additions & 2 deletions apps/studio/src/lib/db/clients/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) 2015 The SQLECTRON Team

import mysql from './mysql';
import mariadb from './mariadb';
import postgresql from './postgresql';
import sqlserver from './sqlserver';
import sqlite from './sqlite';
import cassandra from './cassandra';
import bigquery from './bigquery.js';
import firebird from './firebird';
import { DBClientFactories } from '../types';


export function findClient(key: string): Client | undefined {
Expand Down Expand Up @@ -153,15 +155,17 @@ export const CLIENTS: ClientConfig[] = [
];


export default {
const factories: DBClientFactories = {
mysql,
postgresql,
sqlserver,
sqlite,
cassandra,
redshift: postgresql,
mariadb: mysql,
mariadb,
cockroachdb: postgresql,
bigquery,
firebird,
};

export default factories;
36 changes: 36 additions & 0 deletions apps/studio/src/lib/db/clients/mariadb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { IDbConnectionDatabase, IDbConnectionServer } from "../types";
import { MysqlClient } from "./mysql";

export class MariaDBClient extends MysqlClient {
resolveDefault(defaultValue: string) {
// adapted from https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/pull/998/files
if (!defaultValue) return null;

if (defaultValue.toString().toLowerCase() === "'null'") {
return null;
}

if (
defaultValue.startsWith("'") &&
defaultValue.endsWith("'") &&
defaultValue.length >= 2
) {
// MariaDb escapes all single quotes with two single quotes in default value strings, even if they are
// escaped with backslashes in the original `CREATE TABLE` statement.
return defaultValue
.substring(1, defaultValue.length - 1)
.replaceAll("''", "'");
}

return defaultValue;
}
}

export default async function (
server: IDbConnectionServer,
database: IDbConnectionDatabase
) {
const client = new MariaDBClient(server, database);
await client.connect();
return client;
}