Skip to content

Commit

Permalink
planetscale reusable getConnection func
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Jul 7, 2023
1 parent f82e82b commit 01f65ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"private": true,
"dependencies": {
"@planetscale/database": "^1.8.0",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"itty-router": "^4.0.13",
"prettier": "^2.8.8",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/lib/planetscale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { connect } from "@planetscale/database";

// useful wrapper for planetscale connection
export function getConnection(env) {
const config = {
// this can be set with "wrangler secret put" or through the planetscale integration on cf dashboard
host: env.DATABASE_HOST,
username: env.DATABASE_USERNAME,
password: env.DATABASE_PASSWORD,
fetch: (url, init) => {
delete init["cache"];
return fetch(url, init);
},
};
return connect(config);
}
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "api-wanderer-moe"
name = "api"
main = "./src/index.ts"
compatibility_date = "2023-04-24"

Expand Down

0 comments on commit 01f65ff

Please sign in to comment.