-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from outerbase/bwilmoth/bigquery-dialect
BigQuery Dialect
- Loading branch information
Showing
11 changed files
with
224 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +0,0 @@ | ||
import { CloudflareD1Connection, Outerbase } from '../dist/index.js'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
const port = 4000; | ||
|
||
app.get('/test', async (req, res) => { | ||
// Establish connection to your provider database | ||
const d1 = new CloudflareD1Connection({ | ||
apiKey: '', | ||
accountId: '', | ||
databaseId: '' | ||
}); | ||
|
||
const db = Outerbase(d1); | ||
// const dbSchema = await d1.fetchDatabaseSchema() | ||
|
||
// const { data, query } = await db | ||
// .selectFrom([ | ||
// { table: 'test2', columns: ['*'] } | ||
// ]) | ||
// .query() | ||
|
||
// let { data, query } = await db | ||
// .insert({ fname: 'John' }) | ||
// .into('test2') | ||
// .returning(['id']) | ||
// .query(); | ||
|
||
// let { data, query } = await db | ||
// .update({ fname: 'Johnny' }) | ||
// .into('test2') | ||
// .where(equals('id', '3', d1.dialect)) | ||
// .query(); | ||
|
||
// let { data, query } = await db | ||
// .deleteFrom('test2') | ||
// .where(equals('id', '3')) | ||
// .query(); | ||
|
||
// let data = {} | ||
// let query = await db | ||
// .createTable('test3') | ||
// .schema('public') | ||
// .columns([ | ||
// { name: 'id', type: ColumnDataType.NUMBER, primaryKey: true }, | ||
// { name: 'fname', type: ColumnDataType.STRING } | ||
// ]) | ||
// .toString(); | ||
|
||
// let data = {} | ||
// let query = await db | ||
// .renameTable('test3', 'test4') | ||
// .toString(); | ||
|
||
// let data = {} | ||
// let query = await db | ||
// .dropTable('test4') | ||
// .toString(); | ||
|
||
// let { data } = await db.queryRaw('SELECT * FROM playing_with_neon WHERE id = $1', ['1']); | ||
res.json(data); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Server is running on http://localhost:${port}`); | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,42 @@ | ||
export const PROMPT = ` | ||
Your job is to ONLY return a block of Javascript code for a Cloudflare worker. | ||
You will receive a database schema as a SQL statement to know what tables and columns exist in case you need to interact with the database. | ||
You will also receive an object that describes what this Cloudflare worker does. | ||
Your job is to understand the object and write a Cloudflare worker that accomplishes the desired task. | ||
An expected output would be something like the following: | ||
\`\`\` | ||
export default { | ||
async fetch(request, env, ctx) { | ||
const url = "https://jsonplaceholder.typicode.com/todos/1"; | ||
// gatherResponse returns both content-type & response body as a string | ||
async function gatherResponse(response) { | ||
const { headers } = response; | ||
const contentType = headers.get("content-type") || ""; | ||
if (contentType.includes("application/json")) { | ||
return { contentType, result: JSON.stringify(await response.json()) }; | ||
} | ||
return { contentType, result: response.text() }; | ||
} | ||
const response = await fetch(url); | ||
const { contentType, result } = await gatherResponse(response); | ||
const options = { headers: { "content-type": contentType } }; | ||
return new Response(result, options); | ||
} | ||
}; | ||
\`\`\` | ||
*Rules:* | ||
- Do not return a guide or directions on how to implement it. | ||
- Only return a block of Javascript code! | ||
- The code block should be able to be deployed to Cloudflare Workers. | ||
- Do not return any code on how to setup the database, your only concern is to make Javascript code for this Cloudflare worker. | ||
- If you need to interact with the database you can do so by doing "sdk.query()" and passing in the SQL query you need to run. | ||
Important: Only respond with a single block of Javascript code, nothing else. | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AbstractDialect } from '../index'; | ||
|
||
export class BigQueryDialect extends AbstractDialect { | ||
formatSchemaAndTable(schema: string | undefined, table: string): string { | ||
if (schema) { | ||
return `\`${schema}.${table}\``; | ||
} | ||
return `\`${table}\``; | ||
} | ||
|
||
formatFromSchemaAndTable(schema: string | undefined, table: string): string { | ||
if (schema) { | ||
return `\`${schema}.${table}\``; | ||
} | ||
return `\`${table}\``; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { AbstractDialect } from '../index'; | ||
|
||
export class DuckDbDialect extends AbstractDialect { | ||
formatSchemaAndTable(schema: string | undefined, table: string): string { | ||
return table; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
import { AbstractDialect, ColumnDataType } from '../index'; | ||
import { QueryBuilder } from '../../client'; | ||
import { QueryType } from '../../query-params'; | ||
|
||
export class MySQLDialect extends AbstractDialect { | ||
mapDataType(dataType: ColumnDataType): string { | ||
switch (dataType.toLowerCase()) { | ||
case ColumnDataType.STRING: | ||
return 'VARCHAR(255)'; // MySQL specific VARCHAR length | ||
return 'VARCHAR(255)'; | ||
case ColumnDataType.BOOLEAN: | ||
return 'TINYINT(1)'; // MySQL uses TINYINT for boolean | ||
return 'TINYINT(1)'; | ||
default: | ||
return super.mapDataType(dataType); | ||
} | ||
} | ||
|
||
// select(builder: QueryBuilder, type: QueryType): string { | ||
// return `SELECT MYSQL` | ||
// } | ||
} |
Oops, something went wrong.