K
Kysely2y ago
Joe

NOW() function in kysely

For instance, this statement is valid on Postgres: INSERT INTO films VALUES ('UA502', 'Bananas', 105, NOW()); I was wondering if there was anyways to achieve the same thing in kysely. Thank you 😄
Solution:
```ts import { sql } from "kysely"; db .insertInto("films")...
Jump to solution
8 Replies
Solution
wirekang
wirekang2y ago
import { sql } from "kysely";

db
.insertInto("films")
.values({
created_at: sql`now()`,
})
import { sql } from "kysely";

db
.insertInto("films")
.values({
created_at: sql`now()`,
})
Joe
JoeOP2y ago
Ahhh got it! Thank you 🙂
Joe
JoeOP2y ago
Hi @wirekang, the statement seems to work but I'm getting these error messages. Do you have any ideas getting around that?
wirekang
wirekang2y ago
You are using intelliJ right?
Joe
JoeOP2y ago
Yep! Webstorm Do you think it's an intellij issue?
wirekang
wirekang2y ago
Intellij-based IDE has a feature that automatically detect SQL string in source codes. now() is not an valid sql string so intellij shows the error
Joe
JoeOP2y ago
I see, that makes sense. I'll do a bit of digging. Thanks for your help! 🙏
koskimas
koskimas2y ago
Yep, it seems that Intellij assumes everything inside a sql tag should be a complete SQL statement. now() is not a complete statement. There's probably some config that'll allow arbitrary expression instead of statements. If not, disable/ignore the whole thing.
Want results from more Discord servers?
Add your server