tzezar
tzezar
Explore posts from servers
DTDrizzle Team
Created by Suryansh on 8/7/2024 in #help
Extending Typescript Client Model(Table)
I will give you example, sorry for formatting i am writing from phone oop way:
class User {
id!: number
firstName!: string
lastName!: string

getFullName () {
return this.firstName + " " + this.lastName
}
}

const result = userRepo.findOne(id)
const user = new User(result)
console.log(user.getFullName())
class User {
id!: number
firstName!: string
lastName!: string

getFullName () {
return this.firstName + " " + this.lastName
}
}

const result = userRepo.findOne(id)
const user = new User(result)
console.log(user.getFullName())
fp way:
const getFullName(user) {
return user.firstName + " " + user.lastName
}

const result = userRepo.findOne(id)
console.log(getFullName(result))
const getFullName(user) {
return user.firstName + " " + user.lastName
}

const result = userRepo.findOne(id)
console.log(getFullName(result))
8 replies
DTDrizzle Team
Created by Suryansh on 8/7/2024 in #help
Extending Typescript Client Model(Table)
Second one: use concat and select builder or query builder with https://orm.drizzle.team/docs/rqb#include-custom-fields
8 replies
DTDrizzle Team
Created by Suryansh on 8/7/2024 in #help
Extending Typescript Client Model(Table)
First scenario: you either create class instance with described method and map results to it - each entry will have this method, I dont recommend creating classes in TS tho, but if this is helpfull for you then why not. Or: create function that takes results array / entry object and pass results to it constructing desired shape of data.
8 replies
DTDrizzle Team
Created by Suryansh on 8/7/2024 in #help
Extending Typescript Client Model(Table)
Do you want to have function attached to result that will return fullName or you want to return fullName constructed in db?
8 replies
DTDrizzle Team
Created by jrydberg on 8/3/2024 in #help
How to get the type of transaction from a database?
I did it like this:
export const dbDrizzle = drizzle(pool);

export type DbConn = typeof dbDrizzle;


const getUser = async (db: DbConn, id: number) => {
const [supplier] = await db.select().from(dostawca).where(eq(dostawca.id, id)).execute()
return supplier;
}


await dbDrizzle.transaction(async (db) => {
const user = await getUser(db, 1);
})

const user = await getUser(dbDrizzle, 1);
export const dbDrizzle = drizzle(pool);

export type DbConn = typeof dbDrizzle;


const getUser = async (db: DbConn, id: number) => {
const [supplier] = await db.select().from(dostawca).where(eq(dostawca.id, id)).execute()
return supplier;
}


await dbDrizzle.transaction(async (db) => {
const user = await getUser(db, 1);
})

const user = await getUser(dbDrizzle, 1);
it allows to pass regular db conn or transaction
6 replies
DTDrizzle Team
Created by jrydberg on 8/3/2024 in #help
How to get the type of transaction from a database?
import { type PostgresJsDatabase } from "drizzle-orm/postgres-js";
6 replies
DTDrizzle Team
Created by Liam on 7/31/2024 in #help
There is not enough information to infer relation
I am not sure since i have not used drizzle for so long. Is your relations syntax correct? As i remember i had to set references field
5 replies
KKysely
Created by tzezar on 7/30/2024 in #help
How to delete and insert in one query
as always thank you very much
6 replies
KKysely
Created by tzezar on 7/3/2024 in #help
Is it possible to change type of returned value with jsonBuildObject?
Have you perhaps had time to take a look at it? I still struggle with it.
16 replies