Back to Drizzle Orm

drizzle-orm-pg 0.15.1

changelogs/drizzle-orm-pg/0.15.1.md

0.45.21.4 KB
Original Source

drizzle-orm-pg 0.15.1

Add support for schemas -> PostgreSQL schemas


Drizzle won't append any schema before table definition by default. So if your tables are in public schema drizzle generate -> select * from "users"

But if you will specify any custom schema you want, then drizzle will generate -> select * from "custom_schema"."users"

Warning If you will have tables with same names in different schemas then drizzle will respond with never[] error in result types and error from database

In this case you may use alias syntax


Usage example

typescript
// Table in default schema
const publicUsersTable = pgTable('users', {
	id: serial('id').primaryKey(),
	name: text('name').notNull(),
	verified: boolean('verified').notNull().default(false),
	jsonb: jsonb<string[]>('jsonb'),
	createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
});


// Table in custom schema
const mySchema = pgSchema('mySchema');

const usersTable = mySchema('users', {
	id: serial('id').primaryKey(),
	name: text('name').notNull(),
	verified: boolean('verified').notNull().default(false),
	jsonb: jsonb<string[]>('jsonb'),
	createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
});