1- import { Table } from "../src/schema" ;
2- import { integer , serial , text , timestamp , uuid , varchar } from "../src/types/column-type" ;
1+ import { Table } from "../src/schema" ;
2+ import {
3+ integer ,
4+ serial ,
5+ text ,
6+ timestamp ,
7+ uuid ,
8+ varchar ,
9+ } from "../src/types/column-type" ;
310
411// Define test interfaces
512interface User {
@@ -41,7 +48,7 @@ describe("Schema and Table", () => {
4148 table . column ( "id" , uuid ( ) ) . primaryKey ( ) ;
4249 table . column ( "name" , varchar ( ) ) ;
4350
44- const sql = table . createTableSql ( )
51+ const sql = table . createTableSql ( ) ;
4552 expect ( sql ) . toContain ( `UUID PRIMARY KEY NOT NULL` ) ;
4653 } ) ;
4754
@@ -76,14 +83,18 @@ describe("Schema and Table", () => {
7683 // );
7784
7885 const sql = table . createTableSql ( ) ;
79- expect ( sql ) . toContain ( `"id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid()` ) ;
86+ expect ( sql ) . toContain (
87+ `"id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid()`
88+ ) ;
8089 expect ( sql ) . toContain ( `"createdAt" TIMESTAMP DEFAULT 'now()'` ) ;
8190 } ) ;
8291
8392 it ( "should create a table with foreign key references" , ( ) => {
8493 const table = new Table < Post > ( "posts" ) ;
8594 table . column ( "id" , uuid ( ) ) . primaryKey ( ) . $defaultUUID ( ) ;
86- table . column ( "authorId" , uuid ( ) ) . references ( { table : "users" , column : "id" , onDelete : 'CASCADE' } ) ;
95+ table
96+ . column ( "authorId" , uuid ( ) )
97+ . references ( { table : "users" , column : "id" , onDelete : "CASCADE" } ) ;
8798
8899 const sql = table . createTableSql ( ) ;
89100 expect ( sql ) . toContain ( '"authorId" UUID REFERENCES users(id)' ) ;
@@ -96,9 +107,9 @@ describe("Schema and Table", () => {
96107 table . column ( "email" , varchar ( ) ) . unique ( ) . notNull ( ) ;
97108 table . column ( "age" , integer ( ) ) ;
98109 table
99- . column ( "createdAt" , timestamp ( ) )
100- . default ( "CURRENT_TIMESTAMP" )
101- . notNull ( ) ;
110+ . column ( "createdAt" , timestamp ( ) )
111+ . default ( "CURRENT_TIMESTAMP" )
112+ . notNull ( ) ;
102113
103114 // CREATE TABLE IF NOT EXISTS users (
104115 // "id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
@@ -108,14 +119,17 @@ describe("Schema and Table", () => {
108119 // "createdAt" TIMESTAMP NOT NULL DEFAULT 'CURRENT_TIMESTAMP'
109120 // );
110121 const sql = table . createTableSql ( ) ;
111- expect ( sql ) . toContain ( `"id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid()` ) ;
122+ expect ( sql ) . toContain (
123+ `"id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid()`
124+ ) ;
112125 expect ( sql ) . toContain ( `"name" VARCHAR(255) NOT NULL` ) ;
113126 expect ( sql ) . toContain ( `"email" VARCHAR(255) NOT NULL UNIQUE` ) ;
114127 expect ( sql ) . toContain ( `"age" INTEGER` ) ;
115- expect ( sql ) . toContain ( `"createdAt" TIMESTAMP NOT NULL DEFAULT 'CURRENT_TIMESTAMP'` ) ;
128+ expect ( sql ) . toContain (
129+ `"createdAt" TIMESTAMP NOT NULL DEFAULT 'CURRENT_TIMESTAMP'`
130+ ) ;
116131 } ) ;
117132
118-
119133 it ( "should handle complex table relationships" , ( ) => {
120134 const usersTable = new Table < User > ( "users" ) ;
121135 usersTable . column ( "id" , uuid ( ) ) . primaryKey ( ) ;
@@ -128,12 +142,9 @@ describe("Schema and Table", () => {
128142 postsTable . column ( "authorId" , uuid ( ) ) . notNull ( ) . references ( {
129143 table : "users" ,
130144 column : "id" ,
131- onDelete : ' CASCADE'
145+ onDelete : " CASCADE" ,
132146 } ) ;
133- postsTable
134- . column ( "createdAt" , timestamp ( ) )
135- . $defaultNOW ( )
136- . notNull ( ) ;
147+ postsTable . column ( "createdAt" , timestamp ( ) ) . $defaultNOW ( ) . notNull ( ) ;
137148
138149 const postsSql = postsTable . createTableSql ( ) ;
139150
@@ -145,8 +156,12 @@ describe("Schema and Table", () => {
145156 // "createdAt" TIMESTAMP NOT NULL DEFAULT 'now()'
146157 // );
147158
148- expect ( postsSql ) . toContain ( `"authorId" UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE` ) ;
149- expect ( postsSql ) . toContain ( `"createdAt" TIMESTAMP NOT NULL DEFAULT 'now()'` ) ;
159+ expect ( postsSql ) . toContain (
160+ `"authorId" UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE`
161+ ) ;
162+ expect ( postsSql ) . toContain (
163+ `"createdAt" TIMESTAMP NOT NULL DEFAULT 'now()'`
164+ ) ;
150165 } ) ;
151166 } ) ;
152167} ) ;
0 commit comments