Skip to content

Commit

Permalink
Added tests to all dialects
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelelz committed Dec 17, 2023
1 parent 661a4ee commit 1c694c2
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 31 deletions.
39 changes: 31 additions & 8 deletions integration-tests/tests/libsql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import type { TestFn } from 'ava';
import anyTest from 'ava';
import {
asc,
avg,
avgDistinct,
count,
countDistinct,
eq,
gt,
gte,
inArray,
type InferModel,
max,
min,
Name,
name,
notInArray,
placeholder,
sql,
TransactionRollbackError,
count,
countDistinct,
avg,
avgDistinct,
sum,
sumDistinct,
max,
min
TransactionRollbackError,
} from 'drizzle-orm';
import { drizzle, type LibSQLDatabase } from 'drizzle-orm/libsql';
import { migrate } from 'drizzle-orm/libsql/migrator';
Expand Down Expand Up @@ -126,7 +127,7 @@ const aggregateTable = sqliteTable('aggregate_table', {
a: integer('a'),
b: integer('b'),
c: integer('c'),
nullOnly: integer('null_only')
nullOnly: integer('null_only'),
});

test.before(async (t) => {
Expand Down Expand Up @@ -941,6 +942,28 @@ test.serial('select with group by complex query', async (t) => {
t.deepEqual(result, [{ name: 'Jane' }]);
});

test.serial('select with empty array in inArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(inArray(usersTable.id, []));

t.deepEqual(result, []);
});

test.serial('select with empty array in notInArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(notInArray(usersTable.id, []));

t.deepEqual(result, [{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);
});

test.serial('build query', async (t) => {
const { db } = t.context;

Expand Down
39 changes: 31 additions & 8 deletions integration-tests/tests/mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import anyTest from 'ava';
import Docker from 'dockerode';
import {
asc,
avg,
avgDistinct,
count,
countDistinct,
DefaultLogger,
eq,
gt,
gte,
inArray,
type InferModel,
max,
min,
Name,
notInArray,
placeholder,
sql,
TransactionRollbackError,
sum,
sumDistinct,
count,
countDistinct,
avg,
avgDistinct,
max,
min,
TransactionRollbackError,
} from 'drizzle-orm';
import {
alias,
Expand Down Expand Up @@ -134,7 +135,7 @@ const aggregateTable = mysqlTable('aggregate_table', {
a: int('a'),
b: int('b'),
c: int('c'),
nullOnly: int('null_only')
nullOnly: int('null_only'),
});

interface Context {
Expand Down Expand Up @@ -745,6 +746,28 @@ test.serial('select with group by as column + sql', async (t) => {
t.deepEqual(result, [{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);
});

test.serial('select with empty array in inArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(inArray(usersTable.id, []));

t.deepEqual(result, []);
});

test.serial('select with empty array in notInArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(notInArray(usersTable.id, []));

t.deepEqual(result, [{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);
});

test.serial('select with group by complex query', async (t) => {
const { db } = t.context;

Expand Down
53 changes: 38 additions & 15 deletions integration-tests/tests/pg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,26 @@ import {
arrayContains,
arrayOverlaps,
asc,
avg,
avgDistinct,
count,
countDistinct,
eq,
gt,
gte,
inArray,
lt,
max,
min,
name,
notInArray,
placeholder,
type SQL,
sql,
type SQLWrapper,
TransactionRollbackError,
count,
countDistinct,
avg,
avgDistinct,
sum,
sumDistinct,
max,
min,
TransactionRollbackError,
} from 'drizzle-orm';
import { drizzle, type NodePgDatabase } from 'drizzle-orm/node-postgres';
import { migrate } from 'drizzle-orm/node-postgres/migrator';
Expand All @@ -50,6 +51,7 @@ import {
macaddr,
macaddr8,
type PgColumn,
pgEnum,
pgMaterializedView,
pgTable,
pgTableCreator,
Expand All @@ -64,7 +66,6 @@ import {
uniqueKeyName,
uuid as pgUuid,
varchar,
pgEnum,
} from 'drizzle-orm/pg-core';
import getPort from 'get-port';
import pg from 'pg';
Expand Down Expand Up @@ -149,7 +150,7 @@ const aggregateTable = pgTable('aggregate_table', {
a: integer('a'),
b: integer('b'),
c: integer('c'),
nullOnly: integer('null_only')
nullOnly: integer('null_only'),
});

interface Context {
Expand Down Expand Up @@ -523,7 +524,7 @@ test.serial('select distinct', async (t) => {
const usersDistinctTable = pgTable('users_distinct', {
id: integer('id').notNull(),
name: text('name').notNull(),
age: integer('age').notNull()
age: integer('age').notNull(),
});

await db.execute(sql`drop table if exists ${usersDistinctTable}`);
Expand All @@ -534,7 +535,7 @@ test.serial('select distinct', async (t) => {
{ id: 1, name: 'John', age: 24 },
{ id: 2, name: 'John', age: 25 },
{ id: 1, name: 'Jane', age: 24 },
{ id: 1, name: 'Jane', age: 26 }
{ id: 1, name: 'Jane', age: 26 },
]);
const users1 = await db.selectDistinct().from(usersDistinctTable).orderBy(
usersDistinctTable.id,
Expand All @@ -547,16 +548,16 @@ test.serial('select distinct', async (t) => {
usersDistinctTable,
).orderBy(usersDistinctTable.name);
const users4 = await db.selectDistinctOn([usersDistinctTable.id, usersDistinctTable.age]).from(
usersDistinctTable
).orderBy(usersDistinctTable.id, usersDistinctTable.age)
usersDistinctTable,
).orderBy(usersDistinctTable.id, usersDistinctTable.age);

await db.execute(sql`drop table ${usersDistinctTable}`);

t.deepEqual(users1, [
{ id: 1, name: 'Jane', age: 24 },
{ id: 1, name: 'Jane', age: 26 },
{ id: 1, name: 'John', age: 24 },
{ id: 2, name: 'John', age: 25 }
{ id: 2, name: 'John', age: 25 },
]);

t.deepEqual(users2.length, 2);
Expand All @@ -570,7 +571,7 @@ test.serial('select distinct', async (t) => {
t.deepEqual(users4, [
{ id: 1, name: 'John', age: 24 },
{ id: 1, name: 'Jane', age: 26 },
{ id: 2, name: 'John', age: 25 }
{ id: 2, name: 'John', age: 25 },
]);
});

Expand Down Expand Up @@ -1714,6 +1715,28 @@ test.serial('array types', async (t) => {
t.deepEqual(res, values);
});

test.serial('select with empty array in inArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(inArray(usersTable.id, []));

t.deepEqual(result, []);
});

test.serial('select with empty array in notInArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(notInArray(usersTable.id, []));

t.deepEqual(result, [{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);
});

test.serial('select for ...', (t) => {
const { db } = t.context;

Expand Down
23 changes: 23 additions & 0 deletions integration-tests/tests/postgres.js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
lt,
Name,
name,
notInArray,
placeholder,
type SQL,
sql,
Expand Down Expand Up @@ -1304,6 +1305,28 @@ test.serial('select count w/ custom mapper', async (t) => {
t.deepEqual(res, [{ count: 2 }]);
});

test.serial('select with empty array in inArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(inArray(usersTable.id, []));

t.deepEqual(result, []);
});

test.serial('select with empty array in notInArray', async (t) => {
const { db } = t.context;

await db.insert(usersTable).values([{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);

const result = await db.select({ name: usersTable.name }).from(usersTable)
.where(notInArray(usersTable.id, []));

t.deepEqual(result, [{ name: 'John' }, { name: 'Jane' }, { name: 'Jane' }]);
});

test.serial('select for ...', (t) => {
const { db } = t.context;

Expand Down

0 comments on commit 1c694c2

Please sign in to comment.