"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.__ΩDialect = void 0;
exports.getDialect = getDialect;
exports.quoteId = quoteId;
exports.tableExistsSql = tableExistsSql;
exports.listTablesSql = listTablesSql;
exports.listDatabasesSql = listDatabasesSql;
exports.currentDatabaseSql = currentDatabaseSql;
const sql_1 = require("@deepkit/sql");
const __ΩDialect = ["mysql", "postgres", 'Dialect', 'P.!."Jw#y'];
exports.__ΩDialect = __ΩDialect;
function getDialect(adapter) {
    const name = adapter.getName();
    if (name === 'mysql')
        return 'mysql';
    if (name === 'postgres')
        return 'postgres';
    throw new Error(`Unsupported database dialect: ${name}`);
}
getDialect.__type = [() => sql_1.SQLDatabaseAdapter, 'adapter', () => __ΩDialect, 'getDialect', 'PP7!2"n#/$'];
function quoteId(dialect, name) {
    if (dialect === 'mysql')
        return `\`${name.replace(/`/g, '``')}\``;
    return `"${name.replace(/"/g, '""')}"`;
}
quoteId.__type = [() => __ΩDialect, 'dialect', 'name', 'quoteId', 'Pn!2"&2#&/$'];
function tableExistsSql(dialect, tableName, schema = 'public') {
    if (dialect === 'mysql') {
        return `SHOW TABLES LIKE '${tableName}'`;
    }
    return `SELECT tablename FROM pg_tables WHERE schemaname = '${schema}' AND tablename = '${tableName}'`;
}
tableExistsSql.__type = [() => __ΩDialect, 'dialect', 'tableName', 'schema', 'tableExistsSql', 'Pn!2"&2#"2$&/%'];
function listTablesSql(dialect, schema = 'public') {
    if (dialect === 'mysql') {
        return `SHOW TABLES`;
    }
    return `SELECT tablename FROM pg_tables WHERE schemaname = '${schema}'`;
}
listTablesSql.__type = [() => __ΩDialect, 'dialect', 'schema', 'listTablesSql', 'Pn!2""2#&/$'];
function listDatabasesSql(dialect) {
    if (dialect === 'mysql') {
        return `SHOW DATABASES`;
    }
    return `SELECT datname AS "Database" FROM pg_database WHERE datistemplate = false`;
}
listDatabasesSql.__type = [() => __ΩDialect, 'dialect', 'listDatabasesSql', 'Pn!2"&/#'];
function currentDatabaseSql(dialect) {
    if (dialect === 'mysql') {
        return `SELECT DATABASE()`;
    }
    return `SELECT current_database()`;
}
currentDatabaseSql.__type = [() => __ΩDialect, 'dialect', 'currentDatabaseSql', 'Pn!2"&/#'];
//# sourceMappingURL=dialect.js.map