d1.test.ts — drizzle-orm Source File
Architecture documentation for d1.test.ts, a typescript file in the drizzle-orm codebase. 14 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 0cd869b6_b82b_1b69_7612_7b75f8f371d3["d1.test.ts"] 46ce8b0c_dd54_2020_c1e8_2865e4c5e575["sqlite-common.ts"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 46ce8b0c_dd54_2020_c1e8_2865e4c5e575 3418d3a3_df7d_8999_e21a_2b4339e5aa45["tests"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 3418d3a3_df7d_8999_e21a_2b4339e5aa45 7f26f618_3381_4763_89e6_6503ea1e3ebd["sqlite-common-cache.ts"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 7f26f618_3381_4763_89e6_6503ea1e3ebd a0747176_ae28_8a69_935b_aa8d197ce39a["TestCache"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> a0747176_ae28_8a69_935b_aa8d197ce39a 271b550c_f48f_806e_3db7_b135393b905d["TestGlobalCache"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 271b550c_f48f_806e_3db7_b135393b905d 1fb7c294_0b28_add4_155b_1659a26ba166["tests"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 1fb7c294_0b28_add4_155b_1659a26ba166 a747a5eb_af84_a763_85ed_2a94aae8816c["d1"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> a747a5eb_af84_a763_85ed_2a94aae8816c 6f6d3074_4c5f_2854_792a_e2b784ba4912["shared"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 6f6d3074_4c5f_2854_792a_e2b784ba4912 690f7dfc_0aea_9ee8_d6e7_26bbb3689031["drizzle-orm"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 690f7dfc_0aea_9ee8_d6e7_26bbb3689031 9825ea15_f492_5ec2_8d69_db5f4e0384c9["d1"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 9825ea15_f492_5ec2_8d69_db5f4e0384c9 4dbe8221_9d63_0006_67b3_50d1b3a601af["migrator"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 4dbe8221_9d63_0006_67b3_50d1b3a601af 8d35eaf2_a542_cfd4_fa1a_fafca0f02686["vitest"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 8d35eaf2_a542_cfd4_fa1a_fafca0f02686 5536e6a8_02de_67a7_6eaf_0fd73c9c2d92["common"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> 5536e6a8_02de_67a7_6eaf_0fd73c9c2d92 be4f1824_b255_ba95_9daf_35a679c997bf["utils"] 0cd869b6_b82b_1b69_7612_7b75f8f371d3 --> be4f1824_b255_ba95_9daf_35a679c997bf style 0cd869b6_b82b_1b69_7612_7b75f8f371d3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { D1Database, D1DatabaseAPI } from '@miniflare/d1';
import { createSQLiteDB } from '@miniflare/shared';
import { sql } from 'drizzle-orm';
import type { DrizzleD1Database } from 'drizzle-orm/d1';
import { drizzle } from 'drizzle-orm/d1';
import { migrate } from 'drizzle-orm/d1/migrator';
import { beforeAll, beforeEach, expect, test } from 'vitest';
import { skipTests } from '~/common';
import { randomString } from '~/utils';
import { anotherUsersMigratorTable, tests, usersMigratorTable } from './sqlite-common';
import { TestCache, TestGlobalCache, tests as cacheTests } from './sqlite-common-cache';
const ENABLE_LOGGING = false;
let db: DrizzleD1Database;
let dbGlobalCached: DrizzleD1Database;
let cachedDb: DrizzleD1Database;
beforeAll(async () => {
const sqliteDb = await createSQLiteDB(':memory:');
const d1db = new D1Database(new D1DatabaseAPI(sqliteDb));
db = drizzle(d1db, { logger: ENABLE_LOGGING });
cachedDb = drizzle(d1db, { logger: ENABLE_LOGGING, cache: new TestCache() });
dbGlobalCached = drizzle(d1db, { logger: ENABLE_LOGGING, cache: new TestGlobalCache() });
});
beforeEach((ctx) => {
ctx.sqlite = {
db,
};
ctx.cachedSqlite = {
db: cachedDb,
dbGlobalCached,
};
});
test('migrator', async () => {
await db.run(sql`drop table if exists another_users`);
await db.run(sql`drop table if exists users12`);
await db.run(sql`drop table if exists __drizzle_migrations`);
await migrate(db, { migrationsFolder: './drizzle2/sqlite' });
await db.insert(usersMigratorTable).values({ name: 'John', email: 'email' }).run();
const result = await db.select().from(usersMigratorTable).all();
await db.insert(anotherUsersMigratorTable).values({ name: 'John', email: 'email' }).run();
const result2 = await db.select().from(anotherUsersMigratorTable).all();
expect(result).toEqual([{ id: 1, name: 'John', email: 'email' }]);
expect(result2).toEqual([{ id: 1, name: 'John', email: 'email' }]);
await db.run(sql`drop table another_users`);
await db.run(sql`drop table users12`);
await db.run(sql`drop table __drizzle_migrations`);
});
test('migrator : migrate with custom table', async () => {
const customTable = randomString();
await db.run(sql`drop table if exists another_users`);
await db.run(sql`drop table if exists users12`);
await db.run(sql`drop table if exists ${sql.identifier(customTable)}`);
await migrate(db, { migrationsFolder: './drizzle2/sqlite', migrationsTable: customTable });
// test if the custom migrations table was created
const res = await db.all(sql`select * from ${sql.identifier(customTable)};`);
expect(res.length > 0).toBeTruthy();
// test if the migrated table are working as expected
await db.insert(usersMigratorTable).values({ name: 'John', email: 'email' });
const result = await db.select().from(usersMigratorTable);
expect(result).toEqual([{ id: 1, name: 'John', email: 'email' }]);
await db.run(sql`drop table another_users`);
await db.run(sql`drop table users12`);
await db.run(sql`drop table ${sql.identifier(customTable)}`);
});
skipTests([
// Cannot convert 49,50,55 to a BigInt
'insert bigint values',
// SyntaxError: Unexpected token , in JSON at position 2
'json insert',
'insert many',
'insert many with returning',
/**
* TODO: Fix Bug! The objects should be equal
*
* See #528 for more details.
* Tldr the D1 driver does not execute joins successfully
*/
'partial join with alias',
'full join with alias',
'select from alias',
'join view as subquery',
'cross join',
]);
cacheTests();
tests();
Domain
Dependencies
- TestCache
- TestGlobalCache
- common
- d1
- d1
- drizzle-orm
- migrator
- shared
- sqlite-common-cache.ts
- sqlite-common.ts
- tests
- tests
- utils
- vitest
Source
Frequently Asked Questions
What does d1.test.ts do?
d1.test.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain.
What does d1.test.ts depend on?
d1.test.ts imports 14 module(s): TestCache, TestGlobalCache, common, d1, d1, drizzle-orm, migrator, shared, and 6 more.
Where is d1.test.ts in the architecture?
d1.test.ts is located at integration-tests/tests/sqlite/d1.test.ts (domain: DrizzleORM, directory: integration-tests/tests/sqlite).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free