meow
meow
Explore posts from servers
TTCTheo's Typesafe Cult
Created by meow on 8/25/2024 in #questions
`drizzle-kit push` connection cleanup
When I run drizzle-kit push with postgres.js I get a connection that doesn't get cleaned up. How do I run a post-push cleanup script?
2 replies
DTDrizzle Team
Created by meow on 8/23/2024 in #help
drizzle-kit push connection cleanup
How do I run a cleanup script after drizzle-kit push, such as to kill database connections? Otherwise I noticed that drizzle-kit leaves connections open.
1 replies
DTDrizzle Team
Created by meow on 8/23/2024 in #help
Maximum call stack for transactions
I've been trying to do a transaction over 100k rows (works at 10k) but I've been getting an error for stack size. How do I handle bigger transactions?
Transaction failed. 13 | }
14 | function mergeQueries(queries) {
15 | const result = { sql: "", params: [] };
16 | for (const query of queries) {
17 | result.sql += query.sql;
18 | result.params.push(...query.params);
^
RangeError: Maximum call stack size exceeded.
at mergeQueries (/Users/meow/Projects/psql/node_modules/drizzle-orm/sql/sql.js:18:19)
at /Users/meow/Projects/psql/node_modules/drizzle-orm/sql/sql.js:52:26
at /Users/meow/Projects/psql/node_modules/drizzle-orm/pg-core/query-builders/insert.js:133:53
at /Users/meow/Projects/psql/node_modules/drizzle-orm/pg-core/query-builders/insert.js:141:19
at /Users/meow/Projects/psql/src/db/seed.ts:124:6
Transaction failed. 13 | }
14 | function mergeQueries(queries) {
15 | const result = { sql: "", params: [] };
16 | for (const query of queries) {
17 | result.sql += query.sql;
18 | result.params.push(...query.params);
^
RangeError: Maximum call stack size exceeded.
at mergeQueries (/Users/meow/Projects/psql/node_modules/drizzle-orm/sql/sql.js:18:19)
at /Users/meow/Projects/psql/node_modules/drizzle-orm/sql/sql.js:52:26
at /Users/meow/Projects/psql/node_modules/drizzle-orm/pg-core/query-builders/insert.js:133:53
at /Users/meow/Projects/psql/node_modules/drizzle-orm/pg-core/query-builders/insert.js:141:19
at /Users/meow/Projects/psql/src/db/seed.ts:124:6
3 replies
DTDrizzle Team
Created by meow on 8/18/2024 in #help
Postgres Schema (namespace)
Does anyone have a minimal example of a Drizzle postgres schema that uses the Postgres "Schema" (namespace) feature? On drizzle kit push I keep getting error: schema "meow" does not exist.
import { sql } from "drizzle-orm"
import {
index,
serial,
timestamp,
pgSchema,
text,
} from "drizzle-orm/pg-core"

const schema = pgSchema("meow")

const time = (name="time") => timestamp(name, { withTimezone: true, mode: "date" }).default(sql`CURRENT_TIMESTAMP`).notNull()
const event = schema.enum("event_type", ["click", "buy", "poll"])

export const User = schema.table("user", {
id: text("id").primaryKey(),
email: text("email").unique().notNull(),
hash: text("hash").notNull(),
username: text("username").unique().notNull(),
})
import { sql } from "drizzle-orm"
import {
index,
serial,
timestamp,
pgSchema,
text,
} from "drizzle-orm/pg-core"

const schema = pgSchema("meow")

const time = (name="time") => timestamp(name, { withTimezone: true, mode: "date" }).default(sql`CURRENT_TIMESTAMP`).notNull()
const event = schema.enum("event_type", ["click", "buy", "poll"])

export const User = schema.table("user", {
id: text("id").primaryKey(),
email: text("email").unique().notNull(),
hash: text("hash").notNull(),
username: text("username").unique().notNull(),
})
8 replies
DTDrizzle Team
Created by meow on 6/21/2024 in #help
Raw SQL query (`.execute()` doesn't exist)
I'm trying to run a raw SQL query for sqlite3 with the Bun driver and I'm finding that .execute() doesn't exist. Anyone got any leads?
import Database from "bun:sqlite"
import { drizzle } from "drizzle-orm/bun-sqlite"

/** raw Bun database client */
export const sqlite = new Database("db.sqlite", { strict: true })

/** Drizzle database client */
export const db = drizzle(sqlite)

const email = "[email protected]"

const query = sql<{exists:boolean}>`select exists(${db.select({ n: sql`1` }).from(User).where(eq(User.email, email))}) as exists`
import Database from "bun:sqlite"
import { drizzle } from "drizzle-orm/bun-sqlite"

/** raw Bun database client */
export const sqlite = new Database("db.sqlite", { strict: true })

/** Drizzle database client */
export const db = drizzle(sqlite)

const email = "[email protected]"

const query = sql<{exists:boolean}>`select exists(${db.select({ n: sql`1` }).from(User).where(eq(User.email, email))}) as exists`
1 replies
DTDrizzle Team
Created by meow on 3/14/2024 in #help
Postgres Schema (namespace) + Drizzle
How do I specify a Postgres schema (as in the psql namespace feature) for drizzle.config.ts? A connection string with database?schema=blah hasn't worked for me.
6 replies
TTCTheo's Typesafe Cult
Created by meow on 3/14/2024 in #questions
Drizzle + Postgres Schema
Has anyone figured out how to get Drizzle working with a Postgres schema (the Postgres namespacing feature)? I've tried databaseName?schema=schemaName in my database connection string to no avail.
2 replies
TTCTheo's Typesafe Cult
Created by meow on 7/16/2023 in #questions
TRPC vanilla queries (T3 stack)
Does anyone know how to access trpc vanilla queries (not hooks)?
async function handler() {
const response = await api.example.hello.useQuery() // more like a fetch then a react hook.
console.log(response)
}
async function handler() {
const response = await api.example.hello.useQuery() // more like a fetch then a react hook.
console.log(response)
}
4 replies
TtRPC
Created by meow on 7/16/2023 in #❓-help
TRPC Vanilla Client (T3 stack)
I'm using the T3 stack (Next + TRPC + etc) and I'm trying to figure out how to do vanilla queries that don't come with the baggage of a hook.
const hello = await api.example.hello.useQuery()
const hello = await api.example.hello.useQuery()
4 replies
CDCloudflare Developers
Created by meow on 7/15/2023 in #workers-help
Types for Email Workers
Does anyone know where to go to get the types for email workers?
export default {
async email(message, env, ctx) {
// stuff
}
}
export default {
async email(message, env, ctx) {
// stuff
}
}
2 replies
TTCTheo's Typesafe Cult
Created by meow on 4/28/2023 in #questions
Prisma `delete` a row with composite keys
I’m trying to delete a single row in Prisma using composite keys x, y. Is it possible to write a query like prisma.table.delete({ where: { x, y }) or do you have to use deleteMany , which presumably doesn’t have a limit 1?
3 replies
TtRPC
Created by meow on 4/12/2023 in #❓-help
Enrich the response object for TRPC endpoint
Currently when I hit a trpc endpoint I get something like:
{
result: {
data: ...
}
}
{
result: {
data: ...
}
}
Is there any way to add more metadata, like:
{
result: {
data: ...
}
meta: {
time: 10ms,
}
}
{
result: {
data: ...
}
meta: {
time: 10ms,
}
}
5 replies
TtRPC
Created by meow on 4/10/2023 in #❓-help
TypeScript type for request object for route handlers
So far I've been writing my routes like:
export const router = t.router({
helloWorld: t.procedure.query(async (req) => "Hello World"),
})
export const router = t.router({
helloWorld: t.procedure.query(async (req) => "Hello World"),
})
What would be the type for req if I wanted to extract my handlers like so:
const handler = async (req:?) => "Hello World"

export const router = t.router({
helloWorld: t.procedure.query(hander)
})
const handler = async (req:?) => "Hello World"

export const router = t.router({
helloWorld: t.procedure.query(hander)
})
4 replies