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.

Issue type:

[x] Question [ ] Bug report [ ] Feature request [ ] Documentation issue

Database system/driver:

[ ] Postgres [ ] MSSQL [x] MySQL [x] MariaDB [ ] SQLite3 [ ] Oracle [ ] Amazon Redshift

typed-knex version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Knex.js version: last ?

Hi ! I don’t know if it possible but I have a need. I need to update updated_at’s timestamp each time my table is modified.

But, I would be compatible with mysql, mariadb and sqlite3. So ‘ON UPDATE …’ doesn’t work with sqlite3.

For example, my migration :

export async function up(knex: Knex): Promise<void> {
  await knex.schema.createTable(tableName, (table) => {
    table.uuid('id').notNullable().primary();
    table.string('firstname').notNullable();
    table.string('lastname').notNullable();
    table.string('email').notNullable().unique();
    table.date('birthdate').notNullable();
    table.string('gender', 1).notNullable();
    table.boolean('active').notNullable();
    table.boolean('termsofuse').notNullable();
    table.timestamps(true, true);
  });
}

Do you have any idea, maybe with flags, how to update my table ? Is typed-knex is the good solution ?

I think I will move from objectionJS to typed-knex !

Thanks for you work !

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wwwoutercommented, Sep 25, 2020

Hi, I’ve been using https://github.com/wwwouter/typed-knex#registerBeforeInsertTransform and https://github.com/wwwouter/typed-knex#registerBeforeUpdateTransform for this use case. As long as every update and insert in done through typed-knex, this works perfect. I’ve used this with Postgres and SQLite.

It wasn’t documented yet, but it is now 😄

0reactions
rwanitocommented, Sep 30, 2020

Okay, you’re right. Thanks you for you work, it’s very useful !

Read more comments on GitHub >

github_iconTop Results From Across the Web

When to use "ON UPDATE CASCADE" - Stack Overflow
ON UPDATE CASCADE : SQL Server updates the corresponding rows in the child table when the rows in the parent table are updated....
Read more >
Difference between On Delete Cascade & On Update ...
ON UPDATE CASCADE ON DELETE CASCADE means that if you UPDATE OR DELETE the parent, the change is cascaded to the child. This...
Read more >
DELETE CASCADE and UPDATE CASCADE in SQL Server ...
UPDATE CASCADE: When we create a foreign key using UPDATE CASCADE the referencing rows are updated in the child table when the referenced ......
Read more >
13.1.20.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
If a FOREIGN KEY clause is defined on both tables in a foreign key relationship, making both tables a parent and child, an...
Read more >
Update Cascade - an overview | ScienceDirect Topics
foreign key (sales_name) references salesperson. on delete cascade on update cascade);. create table order_dept_sales (order_no char(9),.
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