Home / File/ type-hints.test.ts — drizzle-orm Source File

type-hints.test.ts — drizzle-orm Source File

Architecture documentation for type-hints.test.ts, a typescript file in the drizzle-orm codebase. 6 imports, 0 dependents.

File typescript 6 imports

Entity Profile

Dependency Diagram

graph LR
  9c29ac75_87dd_9753_be75_8a389ca31b8b["type-hints.test.ts"]
  c1888528_22f2_78cd_a2b9_80fc9f29b8f3["client-rds-data"]
  9c29ac75_87dd_9753_be75_8a389ca31b8b --> c1888528_22f2_78cd_a2b9_80fc9f29b8f3
  591ffa87_509e_0273_b1da_1537e70dd3ef["crypto"]
  9c29ac75_87dd_9753_be75_8a389ca31b8b --> 591ffa87_509e_0273_b1da_1537e70dd3ef
  8d35eaf2_a542_cfd4_fa1a_fafca0f02686["vitest"]
  9c29ac75_87dd_9753_be75_8a389ca31b8b --> 8d35eaf2_a542_cfd4_fa1a_fafca0f02686
  03f5fde2_44b6_3a84_ee88_b2f1461901cc["pg"]
  9c29ac75_87dd_9753_be75_8a389ca31b8b --> 03f5fde2_44b6_3a84_ee88_b2f1461901cc
  3a00d3dc_4c3e_b034_8774_ca007103e041["pg-core"]
  9c29ac75_87dd_9753_be75_8a389ca31b8b --> 3a00d3dc_4c3e_b034_8774_ca007103e041
  710619fb_2785_d9a1_5845_82973ae7bb92["sql"]
  9c29ac75_87dd_9753_be75_8a389ca31b8b --> 710619fb_2785_d9a1_5845_82973ae7bb92
  style 9c29ac75_87dd_9753_be75_8a389ca31b8b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { RDSDataClient } from '@aws-sdk/client-rds-data';
import crypto from 'crypto';
import { expect, test } from 'vitest';

import { drizzle } from '~/aws-data-api/pg';
import { customType, json, PgDialect, pgTable, text, timestamp, uuid, varchar } from '~/pg-core';
import { sql } from '~/sql/sql';

const db = drizzle(new RDSDataClient(), {
	database: '',
	resourceArn: '',
	secretArn: '',
});

test('type hints - case #1', () => {
	const t = pgTable('t', {
		id: varchar('id', { length: 255 }).primaryKey(),
		workspaceID: varchar('workspace_id', { length: 255 }).notNull(),
		description: text('description').notNull(),
		enrichment: json('enrichment').notNull(),
		category: text('category'),
		tags: text('tags').array().notNull(),
		counterpartyName: text('counterparty_name'),
		timePlaced: timestamp('time_placed').notNull(),
		timeSynced: timestamp('time_synced').notNull(),
	});

	const q = db.insert(t).values({
		id: 'id',
		tags: [],
		workspaceID: 'workspaceID',
		enrichment: {},
		category: 'category',
		description: 'description',
		timePlaced: new Date(),
		timeSynced: sql<string>`CURRENT_TIMESTAMP(6)`,
		counterpartyName: 'counterpartyName',
	});

	const query = new PgDialect().sqlToQuery(q.getSQL());

	expect(query.typings).toEqual(['none', 'none', 'none', 'json', 'none', 'none', 'none', 'timestamp']);
});

test('type hints - case #2', () => {
	const prefixedUlid = <Prefix extends string, PrefixedUlid = `${Prefix}_${string}`>(
		name: string,
		opts: { prefix: Prefix },
	) =>
		customType<{ data: PrefixedUlid; driverData: string }>({
			dataType: () => 'uuid',
			toDriver: (value) => {
				return value as string;
			},
			fromDriver: (value) => {
				return `${opts.prefix}_${value}` as PrefixedUlid;
			},
		})(name);

	const calendars = pgTable('calendars', {
		id: uuid('id').primaryKey().default(sql`gen_random_uuid()`),
		orgMembershipId: prefixedUlid('om_id', { prefix: 'om' }).notNull(),
		platform: text('platform').notNull(),
		externalId: text('external_id').notNull(),
		externalData: json('external_data').notNull(),
		updatedAt: timestamp('updated_at').notNull().default(sql`now()`),
		createdAt: timestamp('created_at').notNull().default(sql`now()`),
	});

	const q = db
		.insert(calendars)
		.values({
			id: crypto.randomUUID(),
			orgMembershipId: 'om_id',
			platform: 'platform',
			externalId: 'externalId',
			externalData: {},
		})
		.returning();

	const query = new PgDialect().sqlToQuery(q.getSQL());

	expect(query.typings).toEqual(['uuid', 'none', 'none', 'none', 'json']);
});

Dependencies

  • client-rds-data
  • crypto
  • pg
  • pg-core
  • sql
  • vitest

Frequently Asked Questions

What does type-hints.test.ts do?
type-hints.test.ts is a source file in the drizzle-orm codebase, written in typescript.
What does type-hints.test.ts depend on?
type-hints.test.ts imports 6 module(s): client-rds-data, crypto, pg, pg-core, sql, vitest.
Where is type-hints.test.ts in the architecture?
type-hints.test.ts is located at drizzle-orm/tests/type-hints.test.ts (directory: drizzle-orm/tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free