Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions drizzle-kit/src/cli/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,13 +1029,15 @@ export const connectToSQLite = async (
errors: { code: number; message: string }[];
};

const baseApiUrl = credentials.baseApiUrl ?? 'https://api.cloudflare.com/client/v4';

const remoteCallback: Parameters<typeof drizzle>[0] = async (
sql,
params,
method,
) => {
const res = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${credentials.accountId}/d1/database/${credentials.databaseId}/${
`${baseApiUrl}/accounts/${credentials.accountId}/d1/database/${credentials.databaseId}/${
method === 'values' ? 'raw' : 'query'
}`,
{
Expand Down Expand Up @@ -1071,7 +1073,7 @@ export const connectToSQLite = async (
) => {
const sql = queries.map((q) => q.sql).join('; ');
const res = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${credentials.accountId}/d1/database/${credentials.databaseId}/query`,
`${baseApiUrl}/accounts/${credentials.accountId}/d1/database/${credentials.databaseId}/query`,
{
method: 'POST',
body: JSON.stringify({ sql }),
Expand Down
2 changes: 2 additions & 0 deletions drizzle-kit/src/cli/validations/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const sqliteCredentials = union([
accountId: string().min(1),
databaseId: string().min(1),
token: string().min(1),
baseApiUrl: string().min(1).optional(),
}),
object({
driver: undefined(),
Expand All @@ -30,6 +31,7 @@ export type SqliteCredentials =
accountId: string;
databaseId: string;
token: string;
baseApiUrl?: string;
}
| {
url: string;
Expand Down
34 changes: 34 additions & 0 deletions drizzle-kit/tests/validations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,40 @@ test('d1-http #7', () => {
).toThrowError();
});

test('d1-http #8 - with baseApiUrl', () => {
sqliteCredentials.parse({
dialect: 'sqlite',
driver: 'd1-http',
accountId: 'accountId',
databaseId: 'databaseId',
token: 'token',
baseApiUrl: 'https://custom.api.example.com/v4',
});
});

test('d1-http #9 - without baseApiUrl (optional)', () => {
sqliteCredentials.parse({
dialect: 'sqlite',
driver: 'd1-http',
accountId: 'accountId',
databaseId: 'databaseId',
token: 'token',
});
});

test('d1-http #10 - empty baseApiUrl should fail', () => {
expect(() =>
sqliteCredentials.parse({
dialect: 'sqlite',
driver: 'd1-http',
accountId: 'accountId',
databaseId: 'databaseId',
token: 'token',
baseApiUrl: '',
})
).toThrowError();
});

// omit undefined driver
test('sqlite #1', () => {
expect(
Expand Down