Skip to content

Commit

Permalink
create new singlestore-schemas.test.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriguespn committed Sep 18, 2024
1 parent c38333a commit f86f5a1
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 90 deletions.
8 changes: 1 addition & 7 deletions drizzle-kit/src/cli/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import {
Prefix,
wrapParam,
} from '../validations/common';
import { LibSQLCredentials, libSQLCredentials } from '../validations/libsql';
import { printConfigConnectionIssues as printIssuesLibSql } from '../validations/libsql';
import { LibSQLCredentials, libSQLCredentials, printConfigConnectionIssues as printIssuesLibSql } from '../validations/libsql';
import {
MysqlCredentials,
mysqlCredentials,
Expand All @@ -30,11 +29,6 @@ import {
printConfigConnectionIssues as printIssuesPg,
} from '../validations/postgres';
import { printConfigConnectionIssues as printIssuesSingleStore, singlestoreCredentials, SingleStoreCredentials } from '../validations/singlestore';
import {
printConfigConnectionIssues as printIssuesSingleStore,
SingleStoreCredentials,
singlestoreCredentials,
} from '../validations/singlestore';
import {
printConfigConnectionIssues as printIssuesSqlite,
SqliteCredentials,
Expand Down
80 changes: 0 additions & 80 deletions drizzle-kit/src/cli/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { withStyle } from './validations/outputs';
import type { PostgresCredentials } from './validations/postgres';
import { SingleStoreCredentials } from './validations/singlestore';
import type { SqliteCredentials } from './validations/sqlite';
import { SingleStoreCredentials } from './validations/singlestore';

export const preparePostgresDB = async (
credentials: PostgresCredentials,
Expand Down Expand Up @@ -812,82 +811,3 @@ export const connectToSingleStore = async (
);
process.exit(1);
};

const parseSingleStoreCredentials = (credentials: SingleStoreCredentials) => {
if ('url' in credentials) {
const url = credentials.url;

const connectionUrl = new URL(url);
const pathname = connectionUrl.pathname;

const database = pathname.split('/')[pathname.split('/').length - 1];
if (!database) {
console.error(
'You should specify a database name in connection string (singlestore://USER:PASSWORD@HOST:PORT/DATABASE)',
);
process.exit(1);
}
return { database, url };
} else {
return {
database: credentials.database,
credentials,
};
}
};

export const connectToSingleStore = async (
it: SingleStoreCredentials,
): Promise<{
db: DB;
proxy: Proxy;
database: string;
migrate: (config: MigrationConfig) => Promise<void>;
}> => {
const result = parseSingleStoreCredentials(it);

if (await checkPackage('singlestore')) {
const { createConnection } = await import('mysql2/promise');
const { drizzle } = await import('drizzle-orm/singlestore');
const { migrate } = await import('drizzle-orm/singlestore/migrator');

const connection = result.url
? await createConnection(result.url)
: await createConnection(result.credentials!); // needed for some reason!

const db = drizzle(connection);
const migrateFn = async (config: MigrationConfig) => {
return migrate(db, config);
};

await connection.connect();
const query: DB['query'] = async <T>(
sql: string,
params?: any[],
): Promise<T[]> => {
const res = await connection.execute(sql, params);
return res[0] as any;
};

const proxy: Proxy = async (params: ProxyParams) => {
const result = await connection.query({
sql: params.sql,
values: params.params,
rowsAsArray: params.mode === 'array',
});
return result[0] as any[];
};

return {
db: { query },
proxy,
database: result.database,
migrate: migrateFn,
};
}

console.error(
"To connect to SingleStore database - please install 'mysql2' drivers",
);
process.exit(1);
};
1 change: 0 additions & 1 deletion drizzle-kit/src/jsonStatements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getNewTableName } from './cli/commands/sqlitePushUtils';
import { warning } from './cli/views';
import { CommonSquashedSchema } from './schemaValidator';
import { MySqlKitInternals, MySqlSchema, MySqlSquasher } from './serializer/mysqlSchema';
import { SingleStoreKitInternals, SingleStoreSchema, SingleStoreSquasher } from './serializer/singlestoreSchema';
import { Index, PgSchema, PgSquasher } from './serializer/pgSchema';
import { SingleStoreKitInternals, SingleStoreSchema, SingleStoreSquasher } from './serializer/singlestoreSchema';
import {
Expand Down
3 changes: 1 addition & 2 deletions drizzle-kit/tests/schemaDiffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Database } from 'better-sqlite3';
import { is } from 'drizzle-orm';
import { MySqlSchema, MySqlTable } from 'drizzle-orm/mysql-core';
import { isPgEnum, isPgSequence, PgEnum, PgSchema, PgSequence, PgTable } from 'drizzle-orm/pg-core';
import { SingleStoreSchema } from 'drizzle-orm/singlestore-core';
import { SingleStoreTable } from 'drizzle-orm/singlestore-core';
import { SingleStoreSchema, SingleStoreTable } from 'drizzle-orm/singlestore-core';
import { SQLiteTable } from 'drizzle-orm/sqlite-core';
import * as fs from 'fs';
import { Connection } from 'mysql2/promise';
Expand Down

0 comments on commit f86f5a1

Please sign in to comment.