Skip to content

Commit

Permalink
feat: Add d1 support for kit push
Browse files Browse the repository at this point in the history
  • Loading branch information
akazwz committed Sep 10, 2024
1 parent 239cfa9 commit 8bf8b25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions drizzle-kit/src/cli/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ export const sqlitePush = async (
await db.query('rollback');
process.exit(1);
}
} else if (credentials.driver === "d1-http") {
await db.run(statementsToExecute.join(''));
}
render(`[${chalk.green('✓')}] Changes applied`);
}
Expand Down
8 changes: 7 additions & 1 deletion drizzle-kit/src/cli/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,19 @@ export const connectToSQLite = async (
params,
method,
) => {
let body:string;
if (params.length > 0) {
body = JSON.stringify({ sql, params });
} else {
body = JSON.stringify({ sql });
}
const res = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${credentials.accountId}/d1/database/${credentials.databaseId}/${
method === 'values' ? 'raw' : 'query'
}`,
{
method: 'POST',
body: JSON.stringify({ sql, params }),
body,
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${credentials.token}`,
Expand Down

0 comments on commit 8bf8b25

Please sign in to comment.