Replies: 5 comments 21 replies
-
Gm @JH365, please check this excerpt of drizzle-kit code for hints :P // src/orm-extenstions/d1-driver/wrangler-client.ts
var wrangler_client_exports = {};
__export(wrangler_client_exports, {
execute: () => execute
});
async function execute(query, configPath, dbName) {
try {
const response = await $`NO_D1_WARNING=true wrangler d1 execute ${dbName} --config=${configPath} --command=${query} --json`;
return { results: JSON.parse(response.stdout)[0].results };
} catch (e) {
try {
await $`NO_D1_WARNING=true wrangler d1 execute ${dbName} --config=${configPath} --command=${query}`;
} catch (e1) {
throw new Error(e1.stdout);
}
throw e;
}
} |
Beta Was this translation helpful? Give feedback.
-
Is there a clear consensus on how this should be addressed now? :) |
Beta Was this translation helpful? Give feedback.
-
Came up with a similar temp solution {
"scripts": {
"db:studio": "cross-env LOCAL_DB_PATH=$(find .wrangler/state/v3/d1/miniflare-D1DatabaseObject -type f -name '*.sqlite' -print -quit) drizzle-kit studio"
}
} Instead of specifying the sqlite file path, just grabbing the path of the import type { Config } from 'drizzle-kit';
export default process.env.LOCAL_DB_PATH
? ({
schema: './src/db/schema.ts',
driver: 'better-sqlite',
dbCredentials: {
url: process.env.LOCAL_DB_PATH!
}
} satisfies Config)
: ({
schema: './src/db/schema.ts',
out: './drizzle',
driver: 'd1',
dbCredentials: {
wranglerConfigPath: 'wrangler.toml',
dbName: 'NAME'
}
} satisfies Config); Haven't been able to get it working with the remote D1 db though drizzle-team/drizzle-kit-mirror#289 |
Beta Was this translation helpful? Give feedback.
-
Joining the thread to get it working on Windows. Create $env:DB_URL=(Get-ChildItem .wrangler\state\v3\d1\miniflare-D1DatabaseObject\*.sqlite).FullName
drizzle-kit studio
export default {
schema: './src/lib/server/schema.ts',
out: './migrations',
driver: 'better-sqlite',
dbCredentials: {
url: process.env.DB_URL!
}
} satisfies Config;
"scripts": {
"db:studio": "powershell -ExecutionPolicy Bypass -File start-studio.ps1",
}, Repeat the same steps for unix environment or use cross-env |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing the tips, y'all! Here's the solution I came up with piecing everything together. I'm overall pretty happy with it since I can use Drizzle Studio with my local db, the preview db (for pages previews), and the prod db. https://kevinkipp.com/blog/going-full-stack-on-astro-with-cloudflare-d1-and-drizzle/ |
Beta Was this translation helpful? Give feedback.
-
I am using Drizzle and Cloudflare D1 in my project and I like Drizzle a lot. And while I was trying Drizzle Studio, I found it connected to live database instead of local dev environment. I'd like to know if there is a way to connect to D1 local instance?
Beta Was this translation helpful? Give feedback.
All reactions