-
Notifications
You must be signed in to change notification settings - Fork 331
Open
Labels
apiRelated to library's APIRelated to library's APIenhancementNew feature or requestNew feature or requestmssqlRelated to MS SQL Server (MSSQL)Related to MS SQL Server (MSSQL)mysqlRelated to MySQLRelated to MySQLoracleRelated to OracleRelated to OraclepostgresRelated to PostgreSQLRelated to PostgreSQLsqliteRelated to sqliteRelated to sqlite
Description
Hey 👋
Temporal columns with a default value being current date and time are very common.
Forcing users to do:
import { sql } from 'kysely'
.addColumn('created_at', 'datetime', (cb) => cb.defaultTo(sql`CURRENT_TIMESTAMP`)) // MySQL / SQLite / PostgreSQL / MSSQL
// or
.addColumn('created_at', 'timestampz', (cb) => cb.defaultTo(sql`now()`)) // PostgreSQL
everywhere, is not ideal.
These also come up in issues/discord more often than desired.
There are also other defaultTo
use cases that use raw SQL and are quite common.
Worth considering, but not the only way probably:
- deprecate
defaultTo
. - introduce
defaultLit
for literals (strings, numbers, booleans, etc.). - introduce
defaultRaw
that accepts any raw SQL string, but has autocompletion for the common stuff likeCURRENT_TIMESTAMP
,NOW()
,gen_random_uuid()
, etc. no longer have to importsql
template tag. Better DX.
Another approach, given there's not a lot of these:
- introduce
defaultToCurrentTimestamp()
. - introduce
defaultToNow()
.
Metadata
Metadata
Assignees
Labels
apiRelated to library's APIRelated to library's APIenhancementNew feature or requestNew feature or requestmssqlRelated to MS SQL Server (MSSQL)Related to MS SQL Server (MSSQL)mysqlRelated to MySQLRelated to MySQLoracleRelated to OracleRelated to OraclepostgresRelated to PostgreSQLRelated to PostgreSQLsqliteRelated to sqliteRelated to sqlite