Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(templates/drizzle): Update connection methods #156

Merged
merged 7 commits into from
Oct 22, 2024
3 changes: 1 addition & 2 deletions templates/javascript/drizzle-neondb-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
"author": "azion",
"license": "MIT",
"dependencies": {
"@neondatabase/serverless": "^0.9.3",
"azion": "latest",
"dotenv": "^16.3.1",
"drizzle-orm": "^0.31.2",
"drizzle-orm": "^0.35.2",
"itty-router": "4.0.23"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MainRouter } from "../lib/routers/main-router.js";
import { PageRouter } from "../lib/routers/page-router.js";
import { ApiRouter } from "../lib/routers/api-router.js";
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { pgTable, text, serial } from "drizzle-orm/pg-core";

Expand All @@ -22,11 +21,10 @@ async function handleRequest(request, args) {
});

//Setup Neon connection
const client = neon(
const db = drizzle(
args.connection_url ||
Azion.env.get("DRIZZLE_NEON_CONNECTION_URL")
);
const db = drizzle(client);

//Setup Neon table
const posts = pgTable('posts', {
Expand Down
3 changes: 1 addition & 2 deletions templates/javascript/drizzle-tidb-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
"author": "azion",
"license": "MIT",
"dependencies": {
"@tidbcloud/serverless": "^0.1.1",
"azion": "latest",
"dotenv": "^16.3.1",
"drizzle-orm": "^0.31.2",
"drizzle-orm": "^0.35.2",
"itty-router": "4.0.23"
}
}
17 changes: 8 additions & 9 deletions templates/javascript/drizzle-tidb-sample/src/function/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MainRouter } from "../lib/routers/main-router.js";
import { PageRouter } from "../lib/routers/page-router.js";
import { ApiRouter } from "../lib/routers/api-router.js";
import { connect } from '@tidbcloud/serverless';
import { drizzle } from 'drizzle-orm/tidb-serverless';
import { mysqlTable, int, text } from 'drizzle-orm/mysql-core';

Expand All @@ -22,16 +21,16 @@ async function handleRequest(request, args) {
});

// Setup TiDB connection
const client = connect({
database: args.database || Azion.env.get("DRIZZLE_TIDB_DATABASE"),
host: args.host || Azion.env.get("DRIZZLE_TIDB_HOST"),
password: args.password || Azion.env.get("DRIZZLE_TIDB_PASSWORD"),
port: args.port || Azion.env.get("DRIZZLE_TIDB_PORT"),
username: args.username || Azion.env.get("DRIZZLE_TIDB_USERNAME"),
const db = drizzle({
connection: {
database: args.database || Azion.env.get("DRIZZLE_TIDB_DATABASE"),
host: args.host || Azion.env.get("DRIZZLE_TIDB_HOST"),
password: args.password || Azion.env.get("DRIZZLE_TIDB_PASSWORD"),
port: args.port || Azion.env.get("DRIZZLE_TIDB_PORT"),
username: args.username || Azion.env.get("DRIZZLE_TIDB_USERNAME"),
}
});

const db = drizzle(client);

// Setup TiDB Table
const posts = mysqlTable('posts', {
id: int('id'),
Expand Down
3 changes: 1 addition & 2 deletions templates/javascript/drizzle-turso-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
"author": "azion",
"license": "MIT",
"dependencies": {
"@libsql/client": "^0.5.3",
"azion": "latest",
"dotenv": "^16.3.1",
"drizzle-orm": "^0.31.2",
"drizzle-orm": "^0.35.2",
"itty-router": "4.0.23"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MainRouter } from "../lib/routers/main-router.js";
import { PageRouter } from "../lib/routers/page-router.js";
import { ApiRouter } from "../lib/routers/api-router.js";
import { createClient } from "@libsql/client/web";
import { drizzle } from 'drizzle-orm/libsql';
import { integer, text, sqliteTable } from "drizzle-orm/sqlite-core";

Expand All @@ -21,12 +20,13 @@ async function handleRequest(request, args) {
return new Response(`You are trying something incorrect.`, { status: 200 });
});

//Setup Turso connection
const client = createClient({
url: args.url || Azion.env.get("DRIZZLE_TURSO_URL"),
authToken: args.token || Azion.env.get("DRIZZLE_TURSO_TOKEN"),
// Setup Turso connection
const db = drizzle({
connection: {
url: args.url || Azion.env.get("DRIZZLE_TURSO_URL"),
authToken: args.token || Azion.env.get("DRIZZLE_TURSO_TOKEN"),
}
});
const db = drizzle(client);

// Setup Turso Table
const posts = sqliteTable('posts', {
Expand Down
Loading