thorwebdev
thorwebdev•2y ago

example of kysely running on deno deploy?

Deno Deploy awesomely can connect to postgres directly from the edge https://deno.com/blog/deploy-postgres-at-the-edge so I was hoping to use https://github.com/koskimas/kysely#deno Was trying to make it work like this:
import { Pool } from 'https://deno.land/x/pg@v0.6.1/mod.ts'
import { serve } from 'https://deno.land/std@0.114.0/http/server.ts'
import {
Kysely,
PostgresDialect,
Generated,
ColumnType,
Selectable,
Insertable,
Updateable,
} from 'https://esm.sh/kysely@0.23.4'

console.log(`Function "kysely-postgres" up and running!`)

interface AnimalTable {
id: Generated<number>
animal: string
created_at: Date
}

// Keys of this interface are table names.
interface Database {
animal: AnimalTable
}

// You'd create one of these when you start your app.
const db = new Kysely<Database>({
// Use MysqlDialect for MySQL and SqliteDialect for SQLite.
dialect: new PostgresDialect({
// @ts-ignore
pool: new Pool({
user: 'postgres',
hostname: 'db.bljghubhkofddfrezkhn.supabase.co',
database: 'postgres',
password: Deno.env.get('DB_PASSWORD')!,
port: 5432,
}),
}),
})
import { Pool } from 'https://deno.land/x/pg@v0.6.1/mod.ts'
import { serve } from 'https://deno.land/std@0.114.0/http/server.ts'
import {
Kysely,
PostgresDialect,
Generated,
ColumnType,
Selectable,
Insertable,
Updateable,
} from 'https://esm.sh/kysely@0.23.4'

console.log(`Function "kysely-postgres" up and running!`)

interface AnimalTable {
id: Generated<number>
animal: string
created_at: Date
}

// Keys of this interface are table names.
interface Database {
animal: AnimalTable
}

// You'd create one of these when you start your app.
const db = new Kysely<Database>({
// Use MysqlDialect for MySQL and SqliteDialect for SQLite.
dialect: new PostgresDialect({
// @ts-ignore
pool: new Pool({
user: 'postgres',
hostname: 'db.bljghubhkofddfrezkhn.supabase.co',
database: 'postgres',
password: Deno.env.get('DB_PASSWORD')!,
port: 5432,
}),
}),
})
But am getting Unknown Authentication type, code: 10, message: SCRA
Deno Blog
Connecting to Postgres from the edge
Many serverless at edge products can not connect to Postgres because they don't support TCP. Deno Deploy can.
GitHub
GitHub - koskimas/kysely: A type-safe typescript SQL query builder
A type-safe typescript SQL query builder. Contribute to koskimas/kysely development by creating an account on GitHub.
2 Replies
NDH
NDH•2y ago
Why such an old version of deno std ? you imported 0.114.0 latest is 0.173.0
thorwebdev
thorwebdev•2y ago
Probably because I copy and paste from examples that are not being updated 😬 Thanks @ndh3193 updating deno std import { serve } from "https://deno.land/std@0.175.0/http/server.ts" makes the function runnable, but unfortunately upon invocation I get
TypeError: Deno.writeAll is not a function
at Connection.startup (https://deno.land/x/pg@v0.6.1/connection.ts:51:20)
at Connection.connect (https://deno.land/x/pg@v0.6.1/connection.ts:36:24)
at async Client.connect (https://deno.land/x/pg@v0.6.1/client.ts:16:9)
at async Pool.connect (https://deno.land/x/pg@v0.6.1/pool.ts:57:9)
at async Er.acquireConnection (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:5:3773)
at async dr.acquireConnection (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:85672)
at async cr.provideConnection (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:84647)
at async pe.executeQuery (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:41131)
at async a.execute (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:21370)
at async Server.<anonymous> (file:///src/index.ts:25:24)
TypeError: Deno.writeAll is not a function
at Connection.startup (https://deno.land/x/pg@v0.6.1/connection.ts:51:20)
at Connection.connect (https://deno.land/x/pg@v0.6.1/connection.ts:36:24)
at async Client.connect (https://deno.land/x/pg@v0.6.1/client.ts:16:9)
at async Pool.connect (https://deno.land/x/pg@v0.6.1/pool.ts:57:9)
at async Er.acquireConnection (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:5:3773)
at async dr.acquireConnection (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:85672)
at async cr.provideConnection (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:84647)
at async pe.executeQuery (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:41131)
at async a.execute (https://esm.sh/v106/kysely@0.23.4/deno/kysely.js:2:21370)
at async Server.<anonymous> (file:///src/index.ts:25:24)
Not sure if that's a Deno deploy quirk