Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DX around column default values and common raw SQL usage. #1162

Open
igalklebanov opened this issue Sep 30, 2024 · 0 comments · May be fixed by #1175
Open

Improve DX around column default values and common raw SQL usage. #1162

igalklebanov opened this issue Sep 30, 2024 · 0 comments · May be fixed by #1175
Labels
api Related to library's API enhancement New feature or request mssql Related to MS SQL Server (MSSQL) mysql Related to MySQL oracle Related to Oracle postgres Related to PostgreSQL sqlite Related to sqlite

Comments

@igalklebanov
Copy link
Member

igalklebanov commented Sep 30, 2024

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:

  1. deprecate defaultTo.
  2. introduce defaultLit for literals (strings, numbers, booleans, etc.).
  3. introduce defaultRaw that accepts any raw SQL string, but has autocompletion for the common stuff like CURRENT_TIMESTAMP, NOW(), gen_random_uuid(), etc. no longer have to import sql template tag. Better DX.

Another approach, given there's not a lot of these:

  1. introduce defaultToCurrentTimestamp().
  2. introduce defaultToNow().
@igalklebanov igalklebanov added enhancement New feature or request mysql Related to MySQL sqlite Related to sqlite postgres Related to PostgreSQL api Related to library's API mssql Related to MS SQL Server (MSSQL) oracle Related to Oracle labels Sep 30, 2024
@austinwoon austinwoon linked a pull request Oct 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request mssql Related to MS SQL Server (MSSQL) mysql Related to MySQL oracle Related to Oracle postgres Related to PostgreSQL sqlite Related to sqlite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant