Skip to content

Commit

Permalink
Merge pull request #156 from aziontech/refactor/templates/javascript/…
Browse files Browse the repository at this point in the history
…drizzle

refactor(templates/drizzle): Update connection methods
  • Loading branch information
pablodiehl authored Oct 22, 2024
2 parents 496e54f + 0c7c371 commit f2917e7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
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"
}
}
12 changes: 6 additions & 6 deletions templates/javascript/drizzle-turso-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 { 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

0 comments on commit f2917e7

Please sign in to comment.