Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
0.5.114
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelrk committed Jul 9, 2024
1 parent 19d70d8 commit 5c0b372
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/cli/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// latest version of netzo/cli (see https://github.com/netzo/netzo/releases)
export const VERSION = "0.5.113";
export const VERSION = "0.5.114";

// minimum version of Deno required to run this CLI
// (see https://github.com/denoland/deployctl/blob/main/src/version.ts)
Expand Down
29 changes: 21 additions & 8 deletions lib/plugins/database/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export type DatabaseConfig = DrizzleConfig & {
// deno-lint-ignore ban-types
export type DatabaseState = {};

// WORKAROUND: drizzle-kit has a bug and .$onUpdated(() => new Date().toISOString())
// is somehow currently not updating the updatedAt field. So we do it manually
// until this is resolved upstream in drizzle-orm for the SQLite adapter.
// see https://github.com/drizzle-team/drizzle-orm/issues/2212
// see https://github.com/t3-oss/create-t3-turbo/issues/1082
const resolveData = (data: Record<string, unknown>) => ({
...data,
updatedAt: new Date().toISOString(),
})

/**
* A fresh plugin that registers middleware and handlers to
* to mount RESTful API routes on the `/database` route path.
Expand Down Expand Up @@ -137,21 +147,24 @@ export const database = (config?: DatabaseConfig): Plugin => {
PUT: async (req, ctx) => {
const { tableName, id } = ctx.params;
const table = config.schema![tableName] as any;
const data = await parseRequestBody(req);
const result = await db.update(table).set(data).where(
eq(table.id, id),
).returning();
// WORKAROUND: resolveData until drizzle fixes .$onUpdated(() => new Date().toISOString())
const data = Object.keys(table).includes("updatedAt")
? resolveData(await parseRequestBody(req))
: await parseRequestBody(req);
const result = await db.update(table).set(data).where(eq(table.id, id)).returning();
return Response.json(
Array.isArray(result) ? result[0] : result.rows,
);
},
PATCH: async (req, ctx) => {
const { tableName, id } = ctx.params;
const table = config.schema![tableName] as any;
const data = await parseRequestBody(req);
const result = await db.update(table).set(data).where(
eq(table.id, id),
).returning();
console.log(Object.keys(table))
// WORKAROUND: resolveData until drizzle fixes .$onUpdated(() => new Date().toISOString())
const data = Object.keys(table).includes("updatedAt")
? resolveData(await parseRequestBody(req))
: await parseRequestBody(req);
const result = await db.update(table).set(data).where(eq(table.id, id)).returning();
return Response.json(
Array.isArray(result) ? result[0] : result.rows,
);
Expand Down

0 comments on commit 5c0b372

Please sign in to comment.