Skip to content

Conversation

@igalklebanov
Copy link
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

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

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
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.

@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.

...
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.

4 participants