Skip to content

feat(schema): col.defaultCurrentTimestamp(precision?) [REOPENED]#1454

Open
igalklebanov wants to merge 7 commits intokysely-org:nextfrom
igalklebanov:feat/default-to-current-timestamp
Open

feat(schema): col.defaultCurrentTimestamp(precision?) [REOPENED]#1454
igalklebanov wants to merge 7 commits intokysely-org:nextfrom
igalklebanov:feat/default-to-current-timestamp

Conversation

@igalklebanov
Copy link
Copy Markdown
Member

@igalklebanov igalklebanov commented May 2, 2025

Hey 👋

reopens #1175 by @austinwoon (was accidentally closed when the 0.28 branch was destroyed).

Closes #1162

This PR adds:

db.createTable('table')
  .addColumn(
    'created_at', 
    'timestamptz', 
    (col) => col.defaultCurrentTimestamp() // <---------- this. outputs as `default current_timestamp`
  )
  .execute()

As a shorthand of:

col.defaultTo(sql`current_timestamp`)

You can also:

col.defaultCurrentTimestamp(6) // outputs as `default current_timestamp(6)`

@vercel
Copy link
Copy Markdown

vercel bot commented May 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2025 2:46am

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented May 2, 2025

kysely_koa_example

npm i https://pkg.pr.new/kysely-org/kysely@1454

commit: 3479909

@igalklebanov igalklebanov added enhancement New feature or request api Related to library's API mysql Related to MySQL sqlite Related to sqlite postgres Related to PostgreSQL mssql Related to MS SQL Server (MSSQL) labels May 2, 2025
@igalklebanov igalklebanov force-pushed the feat/default-to-current-timestamp branch from b79fc4b to aeae046 Compare May 2, 2025 22:17
@igalklebanov igalklebanov changed the title feat: default to current timestamp feat: default to current timestamp [REOPENED] May 25, 2025
@igalklebanov igalklebanov force-pushed the feat/default-to-current-timestamp branch from aeae046 to 18ed284 Compare May 25, 2025 11:48
@igalklebanov igalklebanov force-pushed the feat/default-to-current-timestamp branch from 18ed284 to 586f3a5 Compare May 25, 2025 11:53
@igalklebanov igalklebanov requested review from Copilot and koskimas May 25, 2025 14:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a shorthand method, defaultCurrentTimestamp, to simplify setting a column’s default value to the current timestamp with optional precision.

  • Adds a defaultCurrentTimestamp method to column-definition builders.
  • Updates tests to use defaultCurrentTimestamp instead of defaultTo(sqlcurrent_timestamp).
  • Introduces a new date-parser utility with a TimestampPrecision type and corresponding parsing function.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/node/src/schema.test.ts Replaces previous defaultTo usage with defaultCurrentTimestamp.
src/schema/column-definition-builder.ts Adds the defaultCurrentTimestamp method and updates documentation.
src/parser/date-parser.ts Implements parseCurrentTimestamp and defines TimestampPrecision.
src/index.ts Exports TimestampPrecision from the date-parser.

Comment thread src/schema/column-definition-builder.ts
@igalklebanov igalklebanov added the oracle Related to Oracle label May 25, 2025
@igalklebanov igalklebanov changed the title feat: default to current timestamp [REOPENED] feat(schema): col.defaultCurrentTimestamp(precision?) [REOPENED] May 25, 2025
@igalklebanov igalklebanov changed the title feat(schema): col.defaultCurrentTimestamp(precision?) [REOPENED] feat(schema): col.defaultCurrentTimestamp(precision?) [REOPENED] May 25, 2025
@igalklebanov igalklebanov force-pushed the feat/default-to-current-timestamp branch from d88f32a to be8e7f8 Compare May 25, 2025 21:33
@igalklebanov igalklebanov force-pushed the feat/default-to-current-timestamp branch from be8e7f8 to 0afadf7 Compare July 13, 2025 11:24
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from cdd1cd9 to bdeb0e8 Compare July 19, 2025 23:42
Co-authored-by: Austin Woon Quan <43132101+austinwoon@users.noreply.github.com>
minor adjustments to naming and jsdocs.

...
@igalklebanov igalklebanov force-pushed the feat/default-to-current-timestamp branch from f72edb8 to 3479909 Compare July 29, 2025 02:45
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from f13491f to 90d6c71 Compare September 20, 2025 20:12
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from f3c3650 to 9adaf87 Compare September 29, 2025 20:30
@igalklebanov igalklebanov force-pushed the next branch 3 times, most recently from bdf82d9 to 33e2a45 Compare October 11, 2025 22:31
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from f257ae4 to c85d7c2 Compare December 14, 2025 15:03
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from 06eca6f to 500a250 Compare December 21, 2025 23:11
@igalklebanov igalklebanov force-pushed the next branch 5 times, most recently from ebcfe24 to 2ef37b3 Compare January 18, 2026 07:25
@igalklebanov igalklebanov force-pushed the next branch 4 times, most recently from a859b43 to 362a67a Compare February 8, 2026 00:13
@igalklebanov igalklebanov force-pushed the next branch 3 times, most recently from 63af1a3 to 0cf6dcb Compare April 4, 2026 20:47
@igalklebanov igalklebanov force-pushed the next branch 2 times, most recently from ca8e49a to 9f037a2 Compare April 12, 2026 08:52
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 this pull request may close these issues.

5 participants