chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:10:05 +08:00
commit d37d8d293b
1388 changed files with 484182 additions and 0 deletions
@@ -0,0 +1,124 @@
import 'dotenv/config';
import Database from 'better-sqlite3';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import { describe, expect } from 'vitest';
import { sqlite as schema } from './schema.mjs';
describe('better-sqlite3', async (it) => {
it('drizzle()', async () => {
const db = drizzle();
await db.$client.exec('SELECT 1;');
await db.$client.close();
});
it('drizzle(string)', async () => {
const db = drizzle(':memory:');
await db.$client.exec('SELECT 1;');
await db.$client.close();
});
it('drizzle(string, config)', async () => {
const db = drizzle(':memory:', {
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: ':memory:',
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
source: ':memory:',
},
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: {}, ...config})', async () => {
const db = drizzle({
connection: {},
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({...config})', async () => {
const db = drizzle({
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = new Database(':memory:');
const db = drizzle(client);
await db.$client.exec('SELECT 1;');
await db.$client.close();
});
it('drizzle(client, config)', async () => {
const client = new Database(':memory:');
const db = drizzle(client, {
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = new Database(':memory:');
const db = drizzle({
client,
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,97 @@
import 'dotenv/config';
import { createClient } from '@libsql/client';
import { drizzle } from 'drizzle-orm/libsql';
import { describe, expect } from 'vitest';
import { sqlite as schema } from './schema.mjs';
describe('libsql', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(':memory:');
await db.$client.execute('SELECT 1;');
await db.$client.close();
});
it('drizzle(string, config)', async () => {
const db = drizzle(':memory:', {
schema,
});
await db.$client.execute('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: ':memory:',
schema,
});
await db.$client.execute('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
url: ':memory:',
},
schema,
});
await db.$client.execute('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = createClient({
url: ':memory:',
});
const db = drizzle(client);
await db.$client.execute('SELECT 1;');
await db.$client.close();
});
it('drizzle(client, config)', async () => {
const client = createClient({
url: ':memory:',
});
const db = drizzle(client, {
schema,
});
await db.$client.execute('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = createClient({
url: ':memory:',
});
const db = drizzle({
client,
schema,
});
await db.$client.execute('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,153 @@
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/mysql2';
import { Connection, createConnection, createPool } from 'mysql2';
import { describe, expect } from 'vitest';
import { mysql as schema } from './schema.mjs';
if (!process.env['MYSQL_CONNECTION_STRING']) {
throw new Error('MYSQL_CONNECTION_STRING is not defined');
}
describe('mysql2', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(
process.env['MYSQL_CONNECTION_STRING'],
);
await db.$client.execute(`SELECT 1`);
expect(db.$client.getConnection).not.toStrictEqual(undefined);
});
it('drizzle(string, config)', async () => {
const db = drizzle(
process.env['MYSQL_CONNECTION_STRING'],
{
schema,
mode: 'default',
},
);
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client.getConnection).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: process.env['MYSQL_CONNECTION_STRING'],
schema,
mode: 'default',
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client.getConnection).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
uri: process.env['MYSQL_CONNECTION_STRING'],
},
schema,
mode: 'default',
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client.getConnection).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = createPool({
uri: process.env['MYSQL_CONNECTION_STRING'],
});
const db = drizzle(client);
await db.$client.execute('SELECT 1;');
expect(db.$client.getConnection).not.toStrictEqual(undefined);
});
it('drizzle(client, config)', async () => {
const client = createPool({
uri: process.env['MYSQL_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
mode: 'default',
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client.getConnection).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = createPool({
uri: process.env['MYSQL_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
mode: 'default',
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client.getConnection).not.toStrictEqual(undefined);
});
});
describe('mysql2:connection', async (it) => {
it('drizzle(client)', async () => {
const client = createConnection({
uri: process.env['MYSQL_CONNECTION_STRING'],
});
const db = drizzle(client);
await db.$client.execute('SELECT 1;');
expect(db.$client.getConnection).toStrictEqual(undefined);
});
it('drizzle(client, config)', async () => {
const client = createConnection({
uri: process.env['MYSQL_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
mode: 'default',
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client.getConnection).toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = createConnection({
uri: process.env['MYSQL_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
mode: 'default',
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client.getConnection).toStrictEqual(undefined);
});
});
@@ -0,0 +1,92 @@
import 'dotenv/config';
import { neon as pg } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { describe, expect } from 'vitest';
import { pg as schema } from './schema.mjs';
if (!process.env['NEON_CONNECTION_STRING']) {
throw new Error('NEON_CONNECTION_STRING is not defined');
}
describe('neon-http', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(
process.env['NEON_CONNECTION_STRING'],
);
await db.$client('SELECT 1;');
});
it('drizzle(string, config)', async () => {
const db = drizzle(
process.env['NEON_CONNECTION_STRING'],
{
schema,
},
);
await db.$client('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: process.env['NEON_CONNECTION_STRING'],
schema,
});
await db.$client('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
connectionString: process.env['NEON_CONNECTION_STRING'],
},
schema,
});
await db.$client('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = pg(
process.env['NEON_CONNECTION_STRING'],
);
const db = drizzle(client);
await db.$client('SELECT 1;');
});
it('drizzle(client, config)', async () => {
const client = pg(
process.env['NEON_CONNECTION_STRING'],
);
const db = drizzle(client, {
schema,
});
await db.$client('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = pg(
process.env['NEON_CONNECTION_STRING'],
);
const db = drizzle({
client,
schema,
});
await db.$client('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,211 @@
import 'dotenv/config';
import { Client, neonConfig, Pool } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-serverless';
import { describe, expect } from 'vitest';
import ws from 'ws';
import { pg as schema } from './schema.mjs';
neonConfig.webSocketConstructor = ws;
if (!process.env['NEON_CONNECTION_STRING']) {
throw new Error('NEON_CONNECTION_STRING is not defined');
}
describe('neon-ws', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(
process.env['NEON_CONNECTION_STRING'],
);
await db.$client.query('SELECT 1;');
});
it('drizzle(string, config)', async () => {
const db = drizzle(
process.env['NEON_CONNECTION_STRING'],
{
schema,
},
);
await db.$client.query('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: process.env['NEON_CONNECTION_STRING'],
schema,
});
await db.$client.query('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
connectionString: process.env['NEON_CONNECTION_STRING'],
},
schema,
});
await db.$client.query('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle(client)', async () => {
const client = new Pool({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle(client);
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle(client, config)', async () => {
const client = new Pool({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await db.$client.query('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle({client, ...config})', async () => {
const client = new Pool({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
});
await db.$client.query('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Pool);
});
});
describe('neon-ws:Client', async (it) => {
it('drizzle(client)', async () => {
const client = new Client({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
await client.connect();
const db = drizzle(client);
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
expect(db.$client).not.toBeInstanceOf(Pool);
});
it('drizzle(client, config)', async () => {
const client = new Client({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Client);
expect(db.$client).not.toBeInstanceOf(Pool);
});
it('drizzle({client, ...config})', async () => {
const client = new Client({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
});
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Client);
expect(db.$client).not.toBeInstanceOf(Pool);
});
});
describe('neon-ws:PoolClient', async (it) => {
it('drizzle(client)', async () => {
const pool = new Pool({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle(client);
await db.$client.query('SELECT 1;');
client.release();
expect(db.$client).toBeInstanceOf(Client);
expect(db.$client).not.toBeInstanceOf(Pool);
});
it('drizzle(client, config)', async () => {
const pool = new Pool({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle(client, {
schema,
});
await db.$client.query('SELECT 1;');
client.release();
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Client);
expect(db.$client).not.toBeInstanceOf(Pool);
});
it('drizzle({client, ...config})', async () => {
const pool = new Pool({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle({
client,
schema,
});
await db.$client.query('SELECT 1;');
client.release();
expect(db.query.User).not.toStrictEqual(undefined);
expect(db.$client).toBeInstanceOf(Client);
expect(db.$client).not.toBeInstanceOf(Pool);
});
});
@@ -0,0 +1,201 @@
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/node-postgres';
import pg from 'pg';
import { describe, expect } from 'vitest';
import { pg as schema } from './schema.mjs';
const Pool = pg.Pool;
const Client = pg.Client;
if (!process.env['PG_CONNECTION_STRING']) {
throw new Error('PG_CONNECTION_STRING is not defined');
}
describe('node-pg', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(process.env['PG_CONNECTION_STRING']);
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle(string, config)', async () => {
const db = drizzle(process.env['PG_CONNECTION_STRING'], {
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: process.env['PG_CONNECTION_STRING'],
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
connectionString: process.env['PG_CONNECTION_STRING'],
},
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = new Pool({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const db = drizzle(client);
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle(client, config)', async () => {
const client = new Pool({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = new Pool({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeInstanceOf(Pool);
expect(db.query.User).not.toStrictEqual(undefined);
});
});
describe('node-pg:Client', async (it) => {
it('drizzle(client)', async () => {
const client = new Client({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const db = drizzle(client);
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
});
it('drizzle(client, config)', async () => {
const client = new Client({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = new Client({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
});
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
});
describe('node-pg:PoolClient', async (it) => {
it('drizzle(client)', async () => {
const pool = new Pool({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle(client);
await db.$client.query('SELECT 1;');
client.release();
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
});
it('drizzle(client, config)', async () => {
const pool = new Pool({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle(client, {
schema,
});
await db.$client.query('SELECT 1;');
client.release();
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const pool = new Pool({
connectionString: process.env['PG_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle({
client,
schema,
});
await db.$client.query('SELECT 1;');
client.release();
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,88 @@
import 'dotenv/config';
import { PGlite as Database } from '@electric-sql/pglite';
import { drizzle } from 'drizzle-orm/pglite';
import { describe, expect } from 'vitest';
import { pg as schema } from './schema.mjs';
describe('pglite', async (it) => {
it('drizzle()', async () => {
const db = drizzle();
await db.$client.exec('SELECT 1;');
await db.$client.close();
});
it('drizzle(string)', async () => {
const db = drizzle('memory://');
await db.$client.exec('SELECT 1;');
await db.$client.close();
});
it('drizzle(string, config)', async () => {
const db = drizzle('memory://', {
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: {}, ...config})', async () => {
const db = drizzle({
connection: {},
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({...config})', async () => {
const db = drizzle({
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = new Database('memory://');
const db = drizzle(client);
await db.$client.exec('SELECT 1;');
await db.$client.close();
});
it('drizzle(client, config)', async () => {
const client = new Database('memory://');
const db = drizzle(client, {
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = new Database('memory://');
const db = drizzle({
client,
schema,
});
await db.$client.exec('SELECT 1;');
await db.$client.close();
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,101 @@
import 'dotenv/config';
import { Client } from '@planetscale/database';
import { drizzle } from 'drizzle-orm/planetscale-serverless';
import { describe, expect } from 'vitest';
import { mysql as schema } from './schema.mjs';
if (!process.env['PLANETSCALE_CONNECTION_STRING']) {
throw new Error('PLANETSCALE_CONNECTION_STRING is not defined');
}
describe('planetscale', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(
process.env['PLANETSCALE_CONNECTION_STRING'],
);
await db.$client.execute('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
});
it('drizzle(string, config)', async () => {
const db = drizzle(
process.env['PLANETSCALE_CONNECTION_STRING'],
{
schema,
},
);
await db.$client.execute('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: process.env['PLANETSCALE_CONNECTION_STRING'],
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
url: process.env['PLANETSCALE_CONNECTION_STRING'],
},
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = new Client({
url: process.env['PLANETSCALE_CONNECTION_STRING'],
});
const db = drizzle(client);
await db.$client.execute('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
});
it('drizzle(client, config)', async () => {
const client = new Client({
url: process.env['PLANETSCALE_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = new Client({
url: process.env['PLANETSCALE_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,81 @@
import 'dotenv/config';
import { drizzle } from 'drizzle-orm/postgres-js';
import pg from 'postgres';
import { describe, expect } from 'vitest';
import { pg as schema } from './schema.mjs';
if (!process.env['PG_CONNECTION_STRING']) {
throw new Error('PG_CONNECTION_STRING is not defined');
}
describe('postgres-js', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(process.env['PG_CONNECTION_STRING']);
await db.$client.unsafe('SELECT 1;');
});
it('drizzle(string, config)', async () => {
const db = drizzle(process.env['PG_CONNECTION_STRING'], {
schema,
});
await db.$client.unsafe('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: process.env['PG_CONNECTION_STRING'],
schema,
});
await db.$client.unsafe('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
url: process.env['PG_CONNECTION_STRING'],
},
schema,
});
await db.$client.unsafe('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = pg(process.env['PG_CONNECTION_STRING']);
const db = drizzle(client);
await db.$client.unsafe('SELECT 1;');
});
it('drizzle(client, config)', async () => {
const client = pg(process.env['PG_CONNECTION_STRING']);
const db = drizzle(client, {
schema,
});
await db.$client.unsafe('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = pg(process.env['PG_CONNECTION_STRING']);
const db = drizzle({
client,
schema,
});
await db.$client.unsafe('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,21 @@
import { int as mysqlInt, mysqlTable } from 'drizzle-orm/mysql-core';
import { integer as pgInt, pgTable } from 'drizzle-orm/pg-core';
import { integer as sqliteInt, sqliteTable } from 'drizzle-orm/sqlite-core';
export const sqlite = {
User: sqliteTable('test', {
id: sqliteInt('id').primaryKey().notNull(),
}),
};
export const pg = {
User: pgTable('test', {
id: pgInt('id').primaryKey().notNull(),
}),
};
export const mysql = {
User: mysqlTable('test', {
id: mysqlInt('id').primaryKey().notNull(),
}),
};
@@ -0,0 +1,88 @@
import 'dotenv/config';
import { connect } from '@tidbcloud/serverless';
import { drizzle } from 'drizzle-orm/tidb-serverless';
import { describe, expect } from 'vitest';
import { mysql as schema } from './schema.mjs';
if (!process.env['TIDB_CONNECTION_STRING']) {
throw new Error('TIDB_CONNECTION_STRING is not defined');
}
describe('tidb', async (it) => {
it('drizzle(string)', async () => {
const db = drizzle(
process.env['TIDB_CONNECTION_STRING'],
);
await db.$client.execute(`SELECT 1`);
});
it('drizzle(string, config)', async () => {
const db = drizzle(
process.env['TIDB_CONNECTION_STRING'],
{
schema,
},
);
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: string, ...config})', async () => {
const db = drizzle({
connection: process.env['TIDB_CONNECTION_STRING'],
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({connection: params, ...config})', async () => {
const db = drizzle({
connection: {
url: process.env['TIDB_CONNECTION_STRING'],
},
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle(client)', async () => {
const client = connect({
url: process.env['TIDB_CONNECTION_STRING'],
});
const db = drizzle(client);
await db.$client.execute('SELECT 1;');
});
it('drizzle(client, config)', async () => {
const client = connect({
url: process.env['TIDB_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = connect({
url: process.env['TIDB_CONNECTION_STRING'],
});
const db = drizzle({
client,
schema,
});
await db.$client.execute('SELECT 1;');
expect(db.query.User).not.toStrictEqual(undefined);
});
});
@@ -0,0 +1,229 @@
import 'dotenv/config';
import { createClient, createPool, sql, VercelClient, VercelPool } from '@vercel/postgres';
import { drizzle } from 'drizzle-orm/vercel-postgres';
import { describe, expect } from 'vitest';
import { pg as schema } from './schema.mjs';
const Pool = VercelPool;
const Client = VercelClient;
if (!process.env['VERCEL_CONNECTION_STRING']) {
throw new Error('VERCEL_CONNECTION_STRING is not defined');
}
// Used for non-pooled connection
if (!process.env['NEON_CONNECTION_STRING']) {
throw new Error('NEON_CONNECTION_STRING is not defined');
}
process.env['POSTGRES_URL'] = process.env['VERCEL_CONNECTION_STRING'];
describe('vercel:sql', async (it) => {
it('drizzle()', async () => {
const db = drizzle();
await sql.connect();
await db.$client.query('SELECT 1;');
expect(db.$client).toBeTypeOf('function');
});
it('drizzle(client)', async () => {
const db = drizzle(sql);
await db.$client.query('SELECT 1;');
expect(db.$client).toBeTypeOf('function');
});
it('drizzle(client, config)', async () => {
const db = drizzle(sql, {
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeTypeOf('function');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const db = drizzle({
client: sql,
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeTypeOf('function');
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({...config})', async () => {
const db = drizzle({
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).toBeTypeOf('function');
expect(db.query.User).not.toStrictEqual(undefined);
});
});
describe('vercel:Pool', async (it) => {
it('drizzle(client)', async () => {
const client = createPool({
connectionString: process.env['VERCEL_CONNECTION_STRING'],
});
const db = drizzle(client);
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).toBeInstanceOf(Pool);
});
it('drizzle(client, config)', async () => {
const client = createPool({
connectionString: process.env['VERCEL_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).toBeInstanceOf(Pool);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = createPool({
connectionString: process.env['VERCEL_CONNECTION_STRING'],
});
const db = drizzle({
client: client,
schema,
});
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).toBeInstanceOf(Pool);
expect(db.query.User).not.toStrictEqual(undefined);
});
});
describe('vercel:Client', async (it) => {
it('drizzle(client)', async () => {
const client = createClient({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle(client);
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
});
it('drizzle(client, config)', async () => {
const client = createClient({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle(client, {
schema,
});
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const client = createClient({
connectionString: process.env['NEON_CONNECTION_STRING'],
});
const db = drizzle({
client: client,
schema,
});
await client.connect();
await db.$client.query('SELECT 1;');
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
});
describe('vercel:PoolClient', async (it) => {
it('drizzle(client)', async () => {
const pool = createPool({
connectionString: process.env['VERCEL_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle(client);
await db.$client.query('SELECT 1;');
client.release();
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
});
it('drizzle(client, config)', async () => {
const pool = createPool({
connectionString: process.env['VERCEL_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle(client, {
schema,
});
await db.$client.query('SELECT 1;');
client.release();
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
it('drizzle({client, ...config})', async () => {
const pool = createPool({
connectionString: process.env['VERCEL_CONNECTION_STRING'],
});
const client = await pool.connect();
const db = drizzle({
client: client,
schema,
});
await db.$client.query('SELECT 1;');
client.release();
expect(db.$client).not.toBeTypeOf('function');
expect(db.$client).not.toBeInstanceOf(Pool);
expect(db.$client).toBeInstanceOf(Client);
expect(db.query.User).not.toStrictEqual(undefined);
});
});