BluePin
BluePin
Explore posts from servers
DTDrizzle Team
Created by BluePin on 3/26/2024 in #help
Bug Report: Drizzle-kit Introspection Failed to Declare Default Value in SQL
Table introspection fails to find a type declaration for a default value.
ref_icon character varying(255) COLLATE pg_catalog."default" DEFAULT 'activity'::character varying,
ref_icon character varying(255) COLLATE pg_catalog."default" DEFAULT 'activity'::character varying,
Automatic SQL import does not occur and it imports without declaring it to be raw SQL.
import { sql } from 'drizzle-orm';
import { sql } from 'drizzle-orm';
As a result several errors are created in the imported schema.
refIcon: varchar("ref_icon", { length: 255}).default('activity'::character varying`),
refIcon: varchar("ref_icon", { length: 255}).default('activity'::character varying`),
Solution: Introspection must import SQL and make the statement as evidenced in the Documentation:
refIcon: varchar("ref_icon", { length: 255 }).default(
sql`'activity'::character varying`,
),
refIcon: varchar("ref_icon", { length: 255 }).default(
sql`'activity'::character varying`,
),
https://orm.drizzle.team/docs/indexes-constraints
2 replies
TTCTheo's Typesafe Cult
Created by BluePin on 3/22/2024 in #questions
“Integrating Drizzle Prepared Statements with tRPC Context”
I’m currently using tRPC and Drizzle for my project. In tRPC, we generally place the database driver in the context, which allows us to call this variable from within the context and create queries with Drizzle, among other ORMs. This is possible because the database is within the context.
export const createTRPCContext = async (opts: { headers: Headers }) => {
return {
db,
...opts,
};
};
export const createTRPCContext = async (opts: { headers: Headers }) => {
return {
db,
...opts,
};
};
Drizzle has a feature called Prepared Statements that allows me to speed up queries by creating queries with placeholders. This significantly accelerates the query as the SQL binary is already ready and the ORM doesn’t have to pass the logic to the Query Builder, skipping some processing steps.
import { sql } from "drizzle-orm";
const p1 = db
.select()
.from(customers)
.where(eq(customers.id, sql.placeholder('id')))
.prepare("p1")
await p1.execute({ id: 10 }) // SELECT * FROM customers WHERE id = 10
await p1.execute({ id: 12 }) // SELECT * FROM customers WHERE id = 12
const p2 = db
.select()
.from(customers)
.where(sql`lower(${customers.name}) like ${sql.placeholder('name')}`)
.prepare("p2");
await p2.execute({ name: '%an%' }) // SELECT * FROM customers WHERE name ilike '%an%'
import { sql } from "drizzle-orm";
const p1 = db
.select()
.from(customers)
.where(eq(customers.id, sql.placeholder('id')))
.prepare("p1")
await p1.execute({ id: 10 }) // SELECT * FROM customers WHERE id = 10
await p1.execute({ id: 12 }) // SELECT * FROM customers WHERE id = 12
const p2 = db
.select()
.from(customers)
.where(sql`lower(${customers.name}) like ${sql.placeholder('name')}`)
.prepare("p2");
await p2.execute({ name: '%an%' }) // SELECT * FROM customers WHERE name ilike '%an%'
2 replies
TtRPC
Created by BluePin on 3/22/2024 in #❓-help
“Integrating Drizzle Prepared Statements with tRPC Context”
I’m currently using tRPC and Drizzle for my project. In tRPC, we generally place the database driver in the context, which allows us to call this variable from within the context and create queries with Drizzle, among other ORMs. This is possible because the database is within the context.
export const createTRPCContext = async (opts: { headers: Headers }) => {
return {
db,
...opts,
};
};
export const createTRPCContext = async (opts: { headers: Headers }) => {
return {
db,
...opts,
};
};
Drizzle has a feature called Prepared Statements that allows me to speed up queries by creating queries with placeholders. This significantly accelerates the query as the SQL binary is already ready and the ORM doesn’t have to pass the logic to the Query Builder, skipping some processing steps.
import { sql } from "drizzle-orm";
const p1 = db
.select()
.from(customers)
.where(eq(customers.id, sql.placeholder('id')))
.prepare("p1")
await p1.execute({ id: 10 }) // SELECT * FROM customers WHERE id = 10
await p1.execute({ id: 12 }) // SELECT * FROM customers WHERE id = 12
const p2 = db
.select()
.from(customers)
.where(sql`lower(${customers.name}) like ${sql.placeholder('name')}`)
.prepare("p2");
await p2.execute({ name: '%an%' }) // SELECT * FROM customers WHERE name ilike '%an%'
import { sql } from "drizzle-orm";
const p1 = db
.select()
.from(customers)
.where(eq(customers.id, sql.placeholder('id')))
.prepare("p1")
await p1.execute({ id: 10 }) // SELECT * FROM customers WHERE id = 10
await p1.execute({ id: 12 }) // SELECT * FROM customers WHERE id = 12
const p2 = db
.select()
.from(customers)
.where(sql`lower(${customers.name}) like ${sql.placeholder('name')}`)
.prepare("p2");
await p2.execute({ name: '%an%' }) // SELECT * FROM customers WHERE name ilike '%an%'
4 replies
DTDrizzle Team
Created by BluePin on 3/22/2024 in #help
Does anyone know how to write `::character varying` correctly in schema?
refIcon: varchar("ref_icon", { length: 255 }).default('activity'::character varying), I am getting the error: ⚠ Error(TS1005) | , expected. ⚠ Error(TS2554) | Expected 1 arguments, but got 3. ⚠ Error(TS2304) | Cannot find name varying .
2 replies