frankscp
frankscp
DTDrizzle Team
Created by frankscp on 2/4/2024 in #help
can't connect to database in Netflify after adding drizzle, even though it works in localhost
Hello all, I have a sveltekit application (supabase as database, using drizzle as orm) that is working flawlessly in my local machine. However, after my last deploy in which I implemented Drizzle orm as opposed to using supabase api directly, it is completely broke in Netflify. Not only do my endpoints return an error when calling them, but some pages are simply not available and throw a not found error. I suspect in might be related that might not be working for some reason, but so far I haven't found a solution. I even tried to deploy it to vercel, but the exact same error occurred. Any idea on what might be causing this? Thank you
3 replies
DTDrizzle Team
Created by frankscp on 1/15/2024 in #help
How to check if a column of type uuid has a value missing without using sql
Hello, I have a table that references other via foreign key. Both Ids are of type UUID. How can I check if the UUID's value is null using the javascript library? I was expecting 'eq(table1.table2Id, null)' to work, and it actually does at runtime, but I get the following typescript error:
No overload matches this call.
Overload 1 of 3, '(left: PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>, right: string | SQLWrapper): SQL<...>', gave the following error.
Argument of type 'null' is not assignable to parameter of type 'string | SQLWrapper'.
Overload 2 of 3, '(left: Aliased<null>, right: SQLWrapper | null): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased<null>'.
Type 'PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased<null>': sql, fieldAlias
Overload 3 of 3, '(left: never, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'never'.
No overload matches this call.
Overload 1 of 3, '(left: PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>, right: string | SQLWrapper): SQL<...>', gave the following error.
Argument of type 'null' is not assignable to parameter of type 'string | SQLWrapper'.
Overload 2 of 3, '(left: Aliased<null>, right: SQLWrapper | null): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'Aliased<null>'.
Type 'PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>' is missing the following properties from type 'Aliased<null>': sql, fieldAlias
Overload 3 of 3, '(left: never, right: unknown): SQL<unknown>', gave the following error.
Argument of type 'PgColumn<{ name: "table2_id"; tableName: "table1"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>' is not assignable to parameter of type 'never'.
4 replies
DTDrizzle Team
Created by frankscp on 12/14/2023 in #help
Having CRUD functions and Transaction Support
Hello all, I'm using Supabase as my DB and SvelteKit both for the frontend and backend. I decided to create some "CRUD" files, to manage creations and deletions. The purpose would be to set the values of variables such as created_at, created_by (which is a foreign key to user_id), updated_at and updated_by. I was creating my function like this:
import { db } from "$lib/server/connections/drizzle/drizzleClient";
import { person } from "$lib/server/connections/drizzle/schema";
import type { Person } from "$lib/types/database/databaseTypes";

export async function createOrUpdatePerson(inputPerson: Person) {
try {

let response;
// Check if it is update (if the id is already filled)
{
const currentTimestamp = new Date().getTime();
inputPerson.updatedAt= new Date(currentTimestamp).toString();
response = await db.update(person).set(inputPerson).returning({personId: person.id})
}
// If not, it is a creation
else{
const currentTimestamp = new Date().getTime();
inputPerson.createdAt= new Date(currentTimestamp).toString();
response = await db.insert(person).values(inputPerson).returning({personId: person.id})
}
return {success: true}

}
catch(error){
return {success: false, errorMessage: error}
}
}
import { db } from "$lib/server/connections/drizzle/drizzleClient";
import { person } from "$lib/server/connections/drizzle/schema";
import type { Person } from "$lib/types/database/databaseTypes";

export async function createOrUpdatePerson(inputPerson: Person) {
try {

let response;
// Check if it is update (if the id is already filled)
{
const currentTimestamp = new Date().getTime();
inputPerson.updatedAt= new Date(currentTimestamp).toString();
response = await db.update(person).set(inputPerson).returning({personId: person.id})
}
// If not, it is a creation
else{
const currentTimestamp = new Date().getTime();
inputPerson.createdAt= new Date(currentTimestamp).toString();
response = await db.insert(person).values(inputPerson).returning({personId: person.id})
}
return {success: true}

}
catch(error){
return {success: false, errorMessage: error}
}
}
However, I now realized that by doing this, I'll not be able to use transactions. Is there any way I can define that 'updatedAt' should be set to the current timestamp and still use transactions? Thank you!
3 replies
DTDrizzle Team
Created by frankscp on 12/4/2023 in #help
Transaction rolling back without error
Hello all, I'm trying to use Drizzle together with Supabase and SvelteKit to have transaction support. However, I've come across an issue which I'm having trouble understanding. The following query is successful on it's own (the value of the variables is extracted from a form data):
await db.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
await db.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
However, when I use inside a transaction, the transaction does NOT fail, but it does NOT write to the database either:
await db.transaction(async (tx) => {
await tx.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});

});
await db.transaction(async (tx) => {
await tx.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});

});
8 replies