question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export knex.raw('CURRENT_TIMESTAMP') for quick usage

See original GitHub issue

Maybe knex should allow people to write like this:

    table.dateTime('updated_at')
      .defaultTo(knex.CURRENT_TIMESTAMP)

    table.date('day')
      .defaultTo(knex.CURRENT_DATE)

   table.dateTime('timestamp')
      .defaultTo(Date.now)

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

28reactions
bennycodecommented, Sep 7, 2017

For people ending up here from Google. This is the way how to do it in 2017:

const knexfile = require('../../knexfile');
const knex = require('knex')(knexfile.development);
const date = knex.fn.now();
10reactions
squarejawcommented, Oct 22, 2015

This seems to have been implemented by #372.

table.dateTime('updated_at').defaultTo(knex.fn.now());

Might be nice to have some better documentation for this, though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set `updatedAt` timestamp in Knex.js properly?
raw ('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));. But it doesn't work either. How do I make it work? Please help. javascript ...
Read more >
Knex.js: SQL Query Builder for Javascript
Knex.js is a "batteries included" SQL query builder for PostgreSQL, CockroachDB, MSSQL, MySQL, MariaDB, SQLite3, Better-SQLite3, Oracle, and Amazon Redshift ...
Read more >
Knex ❤️ PSQL: updating timestamps like a pro
How to use PSQL trigger functions in Knex.js to keep updated_at in ... the current timestamp when true is passed as the second...
Read more >
egg-knex - npm
If you want to call literals or functions in mysql , you can use raw . Inner Literal. CURRENT_TIMESTAMP(): The database system current...
Read more >
Generated GraphQL: Part 1 - Brandon Konkle
raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";') // timestamp updates await knex.raw(` CREATE OR REPLACE FUNCTION set_updated_at() RETURNS ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found