Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…to main
  • Loading branch information
dankochetov committed Jun 1, 2023
2 parents 24a970c + 2a11e96 commit d425154
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion drizzle-zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
PgCidr,
PgCustomColumn,
PgDate,
PgDateString,
PgDoublePrecision,
PgInet,
PgInteger,
Expand Down Expand Up @@ -299,7 +300,7 @@ function mapColumnToSchema(column: AnyColumn): z.ZodTypeAny {
} else if (
column instanceof PgInterval || column instanceof PgNumeric || column instanceof PgChar
|| column instanceof PgCidr || column instanceof PgInet || column instanceof PgMacaddr
|| column instanceof PgMacaddr8 || column instanceof PgText || column instanceof PgTime
|| column instanceof PgMacaddr8 || column instanceof PgText || column instanceof PgTime || column instanceof PgDateString
|| column instanceof PgVarchar || column instanceof SQLiteNumeric || column instanceof SQLiteText
|| column instanceof MySqlDateString || column instanceof MySqlDateTimeString || column instanceof MySqlDecimal
|| column instanceof MySqlText || column instanceof MySqlTime || column instanceof MySqlTimestampString
Expand Down
12 changes: 11 additions & 1 deletion drizzle-zod/tests/pg.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { integer, pgEnum, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';
import { integer, pgEnum, pgTable, serial, text, timestamp, date } from 'drizzle-orm/pg-core';
import { z } from 'zod';
import { createInsertSchema, createSelectSchema } from '../src';
import { expectSchemaShape } from './utils';
Expand All @@ -11,6 +11,8 @@ const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name'),
email: text('email').notNull(),
birthdayString: date('birthday_string').notNull(),
birthdayDate: date('birthday_date', {mode: "date"}).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
role: roleEnum('role').notNull(),
roleText: text('role1', { enum: ['admin', 'user'] }).notNull(),
Expand Down Expand Up @@ -45,6 +47,8 @@ test('users insert schema', (t) => {
id: z.number().positive().optional(),
name: z.string().nullable().optional(),
email: z.string().email(),
birthdayString: z.string(),
birthdayDate: z.date(),
createdAt: z.date().optional(),
role: z.enum(['admin', 'user']),
roleText: z.enum(['user', 'manager', 'admin']),
Expand All @@ -62,6 +66,8 @@ test('users insert schema w/ defaults', (t) => {
id: z.number().optional(),
name: z.string().nullable().optional(),
email: z.string(),
birthdayString: z.string(),
birthdayDate: z.date(),
createdAt: z.date().optional(),
role: z.enum(['admin', 'user']),
roleText: z.enum(['admin', 'user']),
Expand All @@ -83,6 +89,8 @@ test('users select schema', (t) => {
id: z.number().positive(),
name: z.string().nullable(),
email: z.string().email(),
birthdayString: z.string(),
birthdayDate: z.date(),
createdAt: z.date(),
role: z.enum(['admin', 'user']),
roleText: z.enum(['user', 'manager', 'admin']),
Expand All @@ -100,6 +108,8 @@ test('users select schema w/ defaults', (t) => {
id: z.number(),
name: z.string().nullable(),
email: z.string(),
birthdayString: z.string(),
birthdayDate: z.date(),
createdAt: z.date(),
role: z.enum(['admin', 'user']),
roleText: z.enum(['admin', 'user']),
Expand Down

0 comments on commit d425154

Please sign in to comment.