Comments (1)
You can use this approach with the current Drizzle ORM architecture, so you can have something like this
const commonColumns = {
id: serial('id').primaryKey(),
createdAt: timestamp('created_at', { mode: 'date', withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp('updated_at', { mode: 'date', withTimezone: true })
.notNull()
.defaultNow(),
}
export function abstractTable<
TTableName extends string,
TColumnsMap extends Record<string, PgColumnBuilderBase>,
>(
name: TTableName,
columns: TColumnsMap,
extraConfig?: (self: BuildColumns<TTableName, TColumnsMap & typeof commonColumns, 'pg'>) => PgTableExtraConfig,
) {
const table = pgTable(
name,
{
...commonColumns,
...columns
},
extraConfig,
);
return table;
}
Usage example:
const test = abstractTable('name', {
testColumn: text('t_column')
})
from drizzle-orm.
Related Issues (20)
- [BUG]: drizzle-kit migrate fail "applying migrations...error: column "authorid" does not exist" HOT 5
- [BUG]: drizzle-zod's createInsertSchema() can't handle column of type `vector` HOT 2
- [BUG]: 'left' column name not escaped in index HOT 1
- [BUG]: npx drizzle-kit introspect --> drizzle-kit/bin.cjs:21699 TypeError: Cannot read properties of undefined (reading 'toLowerCase') HOT 1
- [BUG]:
- [BUG]: Losing kysely types (using Kyselify) - getting [x: string]: any HOT 1
- [BUG]: pg array type creation throws error when the type is a composite type
- [BUG]: relation query API default alias is different than regular alias
- [BUG]: `drizzle-kit generate` succeeds but generates invalid SQL for `default([])` - Postgres
- [BUG]: ESLint rule `enforce-delete-with-where` false positive HOT 1
- [BUG]: Migrations not executed in order
- [BUG]: Drizzle doesn't use the schema part of a database connection URL HOT 1
- [BUG]: Geometry config type doesn't appear to affect the output sql
- [BUG]: `drizzle-kit` generate fails to resolve imports HOT 1
- [BUG]: Drizzle migrator doesn't work with uppercase names when creating indexes HOT 1
- [BUG]: pushing to db fails as it automatically adds drop primary key
- [BUG]: point is not exported from "drizzle-orm/pg-core"; HOT 1
- [BUG]: `.if()` does nothing
- [FEATURE]: Unwrap chained relations in `with` operator if `columns` is empty or `false`
- [BUG]: Cloudflare D1 transaction not supported HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drizzle-orm.