initial commit

This commit is contained in:
Kegan Myers 2024-03-02 13:19:49 -06:00
commit 2da08334c3
6 changed files with 1522 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# raw-pg-cloudflare
An example project contrasting how deploys to cloudflare work when using certain node modules (pg), that are impossible to use when using sveltekit.
See [svelte-kit-pg-cloudflare](https://terrible.software/terribleplan/svelte-kit-pg-cloudflare) for the failing sveltekit deployment.

1458
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

15
package.json Normal file
View file

@ -0,0 +1,15 @@
{
"name": "raw-knex-cloudflare",
"version": "0.0.0",
"devDependencies": {
"kysely": "^0.27.2",
"pg": "^8.11.3",
"pg-cursor": "^2.10.3",
"wrangler": "3.30.1"
},
"private": true,
"scripts": {
"start": "wrangler dev",
"deploy": "wrangler deploy"
}
}

29
src/index.js Normal file
View file

@ -0,0 +1,29 @@
import { Kysely, PostgresDialect } from 'kysely';
import { Pool } from 'pg';
import Cursor from 'pg-cursor';
export default {
async fetch(request, { DB }, ctx) {
console.log(JSON.stringify(DB));
const db = new Kysely({
dialect: new PostgresDialect({ pool: new Pool(DB) }),
cursor: Cursor,
});
const users = await db.selectFrom('users').select(['id']).execute();
return new Response(`<html>
<head>
<title>Example</title>
</head>
<body>
<pre>${JSON.stringify(users, null, 2)}</pre>
</body>
</html>
`, {
headers: {
'Content-Type': 'text/html'
}
});
},
};

14
wrangler.toml Normal file
View file

@ -0,0 +1,14 @@
name = "raw-knex-cloudflare"
main = "src/index.js"
compatibility_date = "2024-03-02"
# compatibility_flags = [ "nodejs_compat" ]
# ^ this fails with errors like
# The package "fs" wasn't found on the file system but is built into node.
# Add "node_compat = true" to your wrangler.toml file and make sure to prefix the module name with "node:" to enable Node.js compatibility.
node_compat = true
# ^ it works with the legacy node_compat flag
[[hyperdrive]]
binding = "DB"
id = "<redacted>"