Skip to content

Commit 050dff2

Browse files
committed
Additional merge-related changes
1 parent b2af4f4 commit 050dff2

File tree

40 files changed

+972
-4063
lines changed

40 files changed

+972
-4063
lines changed

compose/singlestore-many.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
singlestore0:
3-
image: ghcr.io/singlestore-labs/singlestoredb-dev:latest
3+
image: ghcr.io/singlestore-labs/singlestoredb-dev:0.2.67
44
environment:
55
ROOT_PASSWORD: singlestore
66
TZ: UTC
@@ -13,7 +13,7 @@ services:
1313
retries: 60
1414

1515
singlestore1:
16-
image: ghcr.io/singlestore-labs/singlestoredb-dev:latest
16+
image: ghcr.io/singlestore-labs/singlestoredb-dev:0.2.67
1717
environment:
1818
ROOT_PASSWORD: singlestore
1919
TZ: UTC
@@ -26,7 +26,7 @@ services:
2626
retries: 60
2727

2828
singlestore2:
29-
image: ghcr.io/singlestore-labs/singlestoredb-dev:latest
29+
image: ghcr.io/singlestore-labs/singlestoredb-dev:0.2.67
3030
environment:
3131
ROOT_PASSWORD: singlestore
3232
TZ: UTC
@@ -39,7 +39,7 @@ services:
3939
retries: 60
4040

4141
singlestore3:
42-
image: ghcr.io/singlestore-labs/singlestoredb-dev:latest
42+
image: ghcr.io/singlestore-labs/singlestoredb-dev:0.2.67
4343
environment:
4444
ROOT_PASSWORD: singlestore
4545
TZ: UTC

compose/singlestore.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
singlestore:
3-
image: ghcr.io/singlestore-labs/singlestoredb-dev:latest
3+
image: ghcr.io/singlestore-labs/singlestoredb-dev:0.2.67
44
environment:
55
ROOT_PASSWORD: singlestore
66
TZ: UTC

drizzle-arktype/src/column.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,26 @@ export const bigintStringModeSchema = type.string.narrow((v, ctx) => {
264264
return true;
265265
});
266266

267+
/** @internal */
268+
export const unsignedBigintStringModeSchema = type.string.narrow((v, ctx) => {
269+
if (typeof v !== 'string') {
270+
return ctx.mustBe('a string');
271+
}
272+
if (!(/^\d+$/.test(v))) {
273+
return ctx.mustBe('a string representing a number');
274+
}
275+
276+
const bigint = BigInt(v);
277+
if (bigint < 0) {
278+
return ctx.mustBe('greater than');
279+
}
280+
if (bigint > CONSTANTS.INT64_MAX) {
281+
return ctx.mustBe('less than');
282+
}
283+
284+
return true;
285+
});
286+
267287
function bigintColumnToSchema(column: Column, constraint?: ColumnDataBigIntConstraint | undefined): Type {
268288
switch (constraint) {
269289
case 'int64': {
@@ -302,6 +322,9 @@ function stringColumnToSchema(column: Column, constraint: ColumnDataStringConstr
302322
if (constraint === 'int64') {
303323
return bigintStringModeSchema;
304324
}
325+
if (constraint === 'uint64') {
326+
return unsignedBigintStringModeSchema;
327+
}
305328

306329
return length && isLengthExact
307330
? type.string.exactlyLength(length)

drizzle-arktype/tests/mysql.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { type Equal, sql } from 'drizzle-orm';
33
import { customType, int, json, mysqlSchema, mysqlTable, mysqlView, serial, text } from 'drizzle-orm/mysql-core';
44
import type { TopLevelCondition } from 'json-rules-engine';
55
import { test } from 'vitest';
6-
import { bigintNarrow, jsonSchema, unsignedBigintNarrow } from '~/column.ts';
6+
import {
7+
bigintNarrow,
8+
bigintStringModeSchema,
9+
jsonSchema,
10+
unsignedBigintNarrow,
11+
unsignedBigintStringModeSchema,
12+
} from '~/column.ts';
713
import { CONSTANTS } from '~/constants.ts';
814
import { createInsertSchema, createSelectSchema, createUpdateSchema } from '../src';
915
import { Expect, expectSchemaShape } from './utils.ts';
@@ -429,8 +435,8 @@ test('all data types', (t) => {
429435
bigint2: type.bigint.narrow(bigintNarrow),
430436
bigint3: type.keywords.number.integer.atLeast(0).atMost(Number.MAX_SAFE_INTEGER),
431437
bigint4: type.bigint.narrow(unsignedBigintNarrow),
432-
bigint5: type.string,
433-
bigint6: type.string,
438+
bigint5: bigintStringModeSchema,
439+
bigint6: unsignedBigintStringModeSchema,
434440
binary: type(`/^[01]{0,10}$/`).describe(
435441
`a string containing ones or zeros while being up to 10 characters long`,
436442
) as Type<string>,

drizzle-arktype/tests/pg.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'drizzle-orm/pg-core';
1616
import type { TopLevelCondition } from 'json-rules-engine';
1717
import { test } from 'vitest';
18-
import { bigintNarrow, jsonSchema } from '~/column.ts';
18+
import { bigintNarrow, bigintStringModeSchema, jsonSchema } from '~/column.ts';
1919
import { CONSTANTS } from '~/constants.ts';
2020
import { createInsertSchema, createSelectSchema, createUpdateSchema } from '../src';
2121
import { Expect, expectEnumValues, expectSchemaShape } from './utils.ts';
@@ -471,7 +471,7 @@ test('all data types', (t) => {
471471
const expected = type({
472472
bigint1: type.keywords.number.integer.atLeast(Number.MIN_SAFE_INTEGER).atMost(Number.MAX_SAFE_INTEGER),
473473
bigint2: type.bigint.narrow(bigintNarrow),
474-
bigint3: type.string,
474+
bigint3: bigintStringModeSchema,
475475
bigserial1: type.keywords.number.integer.atLeast(Number.MIN_SAFE_INTEGER).atMost(Number.MAX_SAFE_INTEGER),
476476
bigserial2: type.bigint.narrow(bigintNarrow),
477477
bit: type(/^[01]{5}$/).describe('a string containing ones or zeros while being 5 characters long'),

drizzle-arktype/tests/singlestore.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import type { Equal } from 'drizzle-orm';
33
import { customType, int, json, serial, singlestoreSchema, singlestoreTable, text } from 'drizzle-orm/singlestore-core';
44
import type { TopLevelCondition } from 'json-rules-engine';
55
import { test } from 'vitest';
6-
import { bigintNarrow, jsonSchema, unsignedBigintNarrow } from '~/column.ts';
6+
import {
7+
bigintNarrow,
8+
bigintStringModeSchema,
9+
jsonSchema,
10+
unsignedBigintNarrow,
11+
unsignedBigintStringModeSchema,
12+
} from '~/column.ts';
713
import { CONSTANTS } from '~/constants.ts';
814
import { createInsertSchema, createSelectSchema, createUpdateSchema } from '../src';
915
import { Expect, expectSchemaShape } from './utils.ts';
@@ -440,8 +446,8 @@ test('all data types', (t) => {
440446
bigint2: type.bigint.narrow(bigintNarrow),
441447
bigint3: type.keywords.number.integer.atLeast(0).atMost(Number.MAX_SAFE_INTEGER),
442448
bigint4: type.bigint.narrow(unsignedBigintNarrow),
443-
bigint5: type.string,
444-
bigint6: type.string,
449+
bigint5: bigintStringModeSchema,
450+
bigint6: unsignedBigintStringModeSchema,
445451
binary: type(`/^[01]{0,10}$/`).describe(
446452
`a string containing ones or zeros while being up to 10 characters long`,
447453
) as Type<string>,

drizzle-kit/src/cli/connections.ts

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PGlite } from '@electric-sql/pglite';
2+
import type { SQLiteCloudRowset } from '@sqlitecloud/drivers';
23
import type { AwsDataApiPgQueryResult, AwsDataApiSessionOptions } from 'drizzle-orm/aws-data-api/pg';
34
import type { MigrationConfig, MigratorInitFailResponse } from 'drizzle-orm/migrator';
45
import type { PreparedQueryConfig } from 'drizzle-orm/pg-core';
@@ -1128,7 +1129,7 @@ export const connectToSQLite = async (
11281129
): Promise<
11291130
& SQLiteDB
11301131
& {
1131-
packageName: 'd1-http' | '@libsql/client' | 'better-sqlite3';
1132+
packageName: 'd1-http' | '@libsql/client' | 'better-sqlite3' | '@sqlitecloud/drivers' | '@tursodatabase/database';
11321133
migrate: (config: string | MigrationConfig) => Promise<void | MigratorInitFailResponse>;
11331134
proxy: Proxy;
11341135
transactionProxy: TransactionProxy;
@@ -1269,6 +1270,90 @@ export const connectToSQLite = async (
12691270
return result.rows;
12701271
};
12711272
return { ...db, packageName: 'd1-http', proxy, transactionProxy, migrate: migrateFn };
1273+
} else if (driver === 'sqlite-cloud') {
1274+
assertPackages('@sqlitecloud/drivers');
1275+
const { Database } = await import('@sqlitecloud/drivers');
1276+
const { drizzle } = await import('drizzle-orm/sqlite-cloud');
1277+
const { migrate } = await import('drizzle-orm/sqlite-cloud/migrator');
1278+
1279+
const client = new Database(credentials.url);
1280+
const drzl = drizzle({ client });
1281+
const migrateFn = async (config: MigrationConfig) => {
1282+
return migrate(drzl, config);
1283+
};
1284+
1285+
const query = async <T>(sql: string, params?: any[]) => {
1286+
const stmt = client.prepare(sql).bind(params || []);
1287+
return await new Promise<T[]>((resolve, reject) => {
1288+
stmt.all((e: Error | null, d: SQLiteCloudRowset) => {
1289+
if (e) return reject(e);
1290+
1291+
return resolve(d.map((v) => Object.fromEntries(Object.entries(v))));
1292+
});
1293+
});
1294+
};
1295+
const run = async (query: string) => {
1296+
return await new Promise<void>((resolve, reject) => {
1297+
client.exec(query, (e: Error | null) => {
1298+
if (e) return reject(e);
1299+
return resolve();
1300+
});
1301+
});
1302+
};
1303+
1304+
const proxy = async (params: ProxyParams) => {
1305+
const preparedParams = prepareSqliteParams(params.params || []);
1306+
const stmt = client.prepare(params.sql).bind(preparedParams);
1307+
return await new Promise<any[]>((resolve, reject) => {
1308+
stmt.all((e: Error | null, d: SQLiteCloudRowset | undefined) => {
1309+
if (e) return reject(e);
1310+
1311+
if (params.mode === 'array') {
1312+
return resolve((d || []).map((v) => v.getData()));
1313+
} else {
1314+
return resolve((d || []).map((v) => Object.fromEntries(Object.entries(v))));
1315+
}
1316+
});
1317+
});
1318+
};
1319+
1320+
const transactionProxy: TransactionProxy = async (queries) => {
1321+
const results: (any[] | Error)[] = [];
1322+
try {
1323+
await new Promise<void>((resolve, reject) => {
1324+
client.exec('BEGIN', (e: Error | null) => {
1325+
if (e) return reject(e);
1326+
return resolve();
1327+
});
1328+
});
1329+
for (const query of queries) {
1330+
const result = await new Promise<any[]>((resolve, reject) => {
1331+
client.all(query.sql, (e: Error | null, d: SQLiteCloudRowset | undefined) => {
1332+
if (e) return reject(e);
1333+
return resolve((d || []).map((v) => Object.fromEntries(Object.entries(v))));
1334+
});
1335+
});
1336+
results.push(result);
1337+
}
1338+
await new Promise<void>((resolve, reject) => {
1339+
client.exec('COMMIT', (e: Error | null) => {
1340+
if (e) return reject(e);
1341+
return resolve();
1342+
});
1343+
});
1344+
} catch (error) {
1345+
results.push(error as Error);
1346+
await new Promise<void>((resolve, reject) => {
1347+
client.exec('ROLLBACK', (e: Error | null) => {
1348+
if (e) return reject(e);
1349+
return resolve();
1350+
});
1351+
});
1352+
}
1353+
return results;
1354+
};
1355+
1356+
return { query, run, packageName: '@sqlitecloud/drivers', proxy, transactionProxy, migrate: migrateFn };
12721357
} else {
12731358
assertUnreachable(driver);
12741359
}
@@ -1341,6 +1426,61 @@ export const connectToSQLite = async (
13411426
return { ...db, packageName: '@libsql/client', proxy, transactionProxy, migrate: migrateFn };
13421427
}
13431428

1429+
if (await checkPackage('@tursodatabase/database')) {
1430+
console.log(withStyle.info(`Using '@tursodatabase/database' driver for database querying`));
1431+
const { Database } = await import('@tursodatabase/database');
1432+
const { drizzle } = await import('drizzle-orm/tursodatabase/database');
1433+
const { migrate } = await import('drizzle-orm/tursodatabase/migrator');
1434+
1435+
const client = new Database(normaliseSQLiteUrl(credentials.url, '@tursodatabase/database'));
1436+
const drzl = drizzle({ client });
1437+
const migrateFn = async (config: MigrationConfig) => {
1438+
return migrate(drzl, config);
1439+
};
1440+
1441+
const query = async <T>(sql: string, params?: any[]) => {
1442+
const stmt = client.prepare(sql).bind(preparePGliteParams(params || []));
1443+
const res = await stmt.all();
1444+
return res as T[];
1445+
};
1446+
1447+
const proxy = async (params: ProxyParams) => {
1448+
const preparedParams = prepareSqliteParams(params.params || []);
1449+
const stmt = client.prepare(params.sql).bind(preparedParams);
1450+
1451+
return stmt.raw(params.mode === 'array').all();
1452+
};
1453+
1454+
const transactionProxy: TransactionProxy = async (queries) => {
1455+
const results: (any[] | Error)[] = [];
1456+
try {
1457+
const tx = client.transaction(async () => {
1458+
for (const query of queries) {
1459+
const result = await client.prepare(query.sql).all();
1460+
results.push(result);
1461+
}
1462+
});
1463+
await tx();
1464+
} catch (error) {
1465+
results.push(error as Error);
1466+
}
1467+
return results;
1468+
};
1469+
1470+
return {
1471+
query,
1472+
packageName: '@tursodatabase/database',
1473+
proxy,
1474+
transactionProxy,
1475+
migrate: migrateFn,
1476+
run: async (query: string) => {
1477+
await client.exec(query).catch((e) => {
1478+
throw new QueryError(e, query, []);
1479+
});
1480+
},
1481+
};
1482+
}
1483+
13441484
if (await checkPackage('better-sqlite3')) {
13451485
const { default: Database } = await import('better-sqlite3');
13461486
const { drizzle } = await import('drizzle-orm/better-sqlite3');

drizzle-kit/src/dialects/mysql/drizzle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export const fromDrizzleSchema = (
228228
return { value: `${getColumnCasing(it, casing)}`, isExpression: false };
229229
}
230230
}),
231-
algorithm: index.config.algorythm ?? null,
231+
algorithm: index.config.algorithm ?? null,
232232
lock: index.config.lock ?? null,
233233
isUnique: index.config.unique ?? false,
234234
using: index.config.using ?? null,

drizzle-kit/src/dialects/singlestore/drizzle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export const fromDrizzleSchema = (
166166
return { value: `${getColumnCasing(it, casing)}`, isExpression: false };
167167
}
168168
}),
169-
algorithm: index.config.algorythm ?? null,
169+
algorithm: index.config.algorithm ?? null,
170170
lock: index.config.lock ?? null,
171171
isUnique: index.config.unique ?? false,
172172
using: index.config.using ?? null,

drizzle-kit/src/utils/utils-node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export const validateWithReport = (snapshots: string[], dialect: Dialect) => {
300300

301301
export const normaliseSQLiteUrl = (
302302
it: string,
303-
type: 'libsql' | 'better-sqlite',
303+
type: 'libsql' | 'better-sqlite' | '@tursodatabase/database',
304304
) => {
305305
if (type === 'libsql') {
306306
if (it.startsWith('file:')) {
@@ -317,7 +317,7 @@ export const normaliseSQLiteUrl = (
317317
}
318318
}
319319

320-
if (type === 'better-sqlite') {
320+
if (type === 'better-sqlite' || type === '@tursodatabase/database') {
321321
if (it.startsWith('file:')) {
322322
return it.substring(5);
323323
}

0 commit comments

Comments
 (0)