Gabriel Lucena
Gabriel Lucena
Explore posts from servers
DTDrizzle Team
Created by Gabriel Lucena on 11/18/2024 in #help
Running SQL statement manually for in-memory database
I have an in-memory sqlite database:
import { readdir } from "node:fs/promises"
import path from "path"
import { createClient } from "@libsql/client/node"
import { drizzle } from "drizzle-orm/libsql"

const client = createClient({
url: ":memory:",
})

export const db = drizzle(client, { logger: true })

migrate()

export async function migrate() {
const migrations = path.resolve(__dirname, "migrations")

const files = await readdir(migrations)

for (const file of files) {
if (file.endsWith(".sql")) {
const read = Bun.file(path.resolve(migrations, file))

const sql = await read.text()

const result = await db.run(sql)

console.log("result", result)
}
}
}
import { readdir } from "node:fs/promises"
import path from "path"
import { createClient } from "@libsql/client/node"
import { drizzle } from "drizzle-orm/libsql"

const client = createClient({
url: ":memory:",
})

export const db = drizzle(client, { logger: true })

migrate()

export async function migrate() {
const migrations = path.resolve(__dirname, "migrations")

const files = await readdir(migrations)

for (const file of files) {
if (file.endsWith(".sql")) {
const read = Bun.file(path.resolve(migrations, file))

const sql = await read.text()

const result = await db.run(sql)

console.log("result", result)
}
}
}
and I'm having trouble running migrations on that database
25 replies
DTDrizzle Team
Created by Gabriel Lucena on 5/31/2024 in #help
Help querying D1 with Drizzle
I was able to run migrations with this drizzle.config.ts:
import { defineConfig } from "drizzle-kit"

import { env } from "./env.mjs"

export default defineConfig({
dialect: "sqlite",
driver: "d1-http",
out: "./src/data/migrations",
schema: "./src/data/schema/*",
migrations: { table: "migrations" },
dbCredentials: {
accountId: env.CLOUDFLARE_ACCOUNT_ID,
databaseId: env.CLOUDFLARE_DATABASE_ID,
token: env.CLOUDFLARE_TOKEN,
},
})
import { defineConfig } from "drizzle-kit"

import { env } from "./env.mjs"

export default defineConfig({
dialect: "sqlite",
driver: "d1-http",
out: "./src/data/migrations",
schema: "./src/data/schema/*",
migrations: { table: "migrations" },
dbCredentials: {
accountId: env.CLOUDFLARE_ACCOUNT_ID,
databaseId: env.CLOUDFLARE_DATABASE_ID,
token: env.CLOUDFLARE_TOKEN,
},
})
but I'm not sure how to connect with the database to run queries on it, one previous example I've used with RDS was:
const client = new RDSDataClient({})

export const db = drizzle(client)
const client = new RDSDataClient({})

export const db = drizzle(client)
does anyone knows how can I do the same but with D1?
9 replies
TtRPC
Created by Gabriel Lucena on 5/10/2024 in #❓-help
How can I add React to SST's TRPC example?
SST recently release an example on how to deploy TRCP to AWS, it's pretty cool! but I'm wondering how can I add react to it's client so I have both worlds: Repo: https://github.com/sst/ion/blob/dev/examples/aws-trpc/client.ts Docs: https://ion.sst.dev/docs/start/aws/trpc/
4 replies
DTDrizzle Team
Created by Gabriel Lucena on 2/11/2024 in #help
defaultFn not nullable
No description
2 replies
DTDrizzle Team
Created by Gabriel Lucena on 1/20/2024 in #help
help with drizzle-zod with jsonb column
No description
4 replies