On update ?
See original GitHub issueIssue 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:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 😄
Okay, you’re right. Thanks you for you work, it’s very useful !