Kysely Database
typescript
How to represent date/time types
Example Output
Generated from the pet-store sample schema:
typescript
// Generated by @sqldoc/templates/kysely -- DO NOT EDIT
import type { Generated } from 'kysely'
export interface AdoptionTable {
id: Generated<number>
pet_id: number
owner_id: number
adopted_at: Generated<Date>
adoption_fee: Generated<string>
}
export interface AdoptionsAuditLogTable {
id: Generated<number>
table_name: string
operation: string
old_data: unknown | null
new_data: unknown | null
changed_at: Generated<Date>
}
export interface CategoryTable {
id: Generated<number>
name: string
description: string | null
}
export interface LegacyInventoryTable {
id: Generated<number>
item_name: string | null
old_sku: string | null
quantity: Generated<number | null>
}
export interface LocationTable {
id: Generated<number>
name: string
address: string
city: string
zip: string | null
}
export interface MedicalRecordTable {
id: Generated<number>
pet_id: number
visit_date: Generated<string>
diagnosis: string
treatment: string | null
vet_name: string | null
}
export interface OwnerTable {
id: Generated<number>
name: string
email: string
phone: string | null
created_at: Generated<Date | null>
}
export interface PetTable {
id: Generated<number>
category_id: number | null
name: string
sku: string
price: Generated<string>
internal_notes: string | null
status: Generated<string>
created_at: Generated<Date | null>
}
export interface ReviewTable {
id: Generated<number>
pet_id: number
owner_id: number
rating: number
body: string | null
location_id: number | null
created_at: Generated<Date | null>
}
export interface StaffAuditLogTable {
id: Generated<number>
table_name: string
operation: string
old_data: unknown | null
new_data: unknown | null
changed_at: Generated<Date>
}
export interface Database {
adoptions: AdoptionTable
adoptions_audit_log: AdoptionsAuditLogTable
categories: CategoryTable
legacy_inventory: LegacyInventoryTable
locations: LocationTable
medical_records: MedicalRecordTable
owners: OwnerTable
pets: PetTable
reviews: ReviewTable
staff_audit_log: StaffAuditLogTable
}Usage
Add to your sqldoc.config.ts:
typescript
export default {
dialect: 'postgres',
schema: ['./schema.sql'],
codegen: [
{
template: 'kysely',
output: './generated/types.ts',
config: {
// See configuration options below
},
},
],
}Then run:
bash
sqldoc codegen