The reason why I want to use knex is because Directus uses knex js and I am thinking, it would be am

The reason why I want to use knex is because Directus uses knex js and I am thinking, it would be amazing to deploy Directus with CloudFlare D1
16 Replies
Max (@rozenmd)
Max (@rozenmd)•15mo ago
Bear in mind that the linked comments are not promises - "we'd like to"/"it's planned" !== coming by date X with certainty
Unsmart
Unsmart•15mo ago
Dynamic bindings did say "will be part of/ahead of GA" 😛 but yes
Matt Silverlock
Matt Silverlock•15mo ago
Still not promises. Team is working on shipping a lot, and we want to be transparent with timelines, but these are not guarantees.
Epailes
Epailes•15mo ago
Good to know it's at least up there on the priority list even if it doesn't end up making GA!
bun
bun•15mo ago
what does GA mean?
Unsmart
Unsmart•15mo ago
generally available aka production ready
bun
bun•15mo ago
so they just mean that those features will be available once its production ready ? like not in beta?
Unsmart
Unsmart•15mo ago
Yes, and its more of a plan to have them so it might be ready might be after
bun
bun•15mo ago
ok but why does this not work
await this.db.batch([
this.db.insert(blobs).values({ hash: blobHash }),
this.db
.insert(assets)
.values({ projectId, blobId: sql`last_insert_rowid()` })
.returning({ assetId: assets.id }),
]);
await this.db.batch([
this.db.insert(blobs).values({ hash: blobHash }),
this.db
.insert(assets)
.values({ projectId, blobId: sql`last_insert_rowid()` })
.returning({ assetId: assets.id }),
]);
[cause]: Error: FOREIGN KEY constraint failed like what
Unsmart
Unsmart•15mo ago
No clue I dont use SQL 🤷
bun
bun•15mo ago
what do you use then
Unsmart
Unsmart•15mo ago
On cloudflare I use durable objects :NODDER:
bun
bun•15mo ago
idk i couuldnt ever get used to workin with durable objects. they seem great at first but even for a simple key value store i have to write a class? like what yeah its probably the blobId, but shouldnt last_insert_rowid() return the id of the latest inserted blob ? as in the first batch statement?
bun
bun•15mo ago
No description
No description
No description
bun
bun•15mo ago
do you prefer raw sql ?
CREATE TABLE `assets` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`ref_count` integer DEFAULT 1 NOT NULL,
`blob_id` integer NOT NULL,
`user_id` integer NOT NULL,
`created_at` integer DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`blob_id`) REFERENCES `blobs`(`id`) ON UPDATE cascade ON DELETE restrict,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE cascade ON DELETE restrict
);

CREATE TABLE `blobs` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`hash` text NOT NULL
);
CREATE TABLE `assets` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`ref_count` integer DEFAULT 1 NOT NULL,
`blob_id` integer NOT NULL,
`user_id` integer NOT NULL,
`created_at` integer DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
FOREIGN KEY (`blob_id`) REFERENCES `blobs`(`id`) ON UPDATE cascade ON DELETE restrict,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE cascade ON DELETE restrict
);

CREATE TABLE `blobs` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`hash` text NOT NULL
);

Did you find this page helpful?