Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 769a5c4

Browse files
committed
add support for postgresql driver in function sdk
1 parent 7ff3fb0 commit 769a5c4

File tree

13 files changed

+3376
-0
lines changed

13 files changed

+3376
-0
lines changed

examples/postgresql/.eslintrc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"env": {
3+
"es6": true
4+
},
5+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
6+
"parser": "@typescript-eslint/parser",
7+
"parserOptions": {
8+
"ecmaVersion": "latest",
9+
"sourceType": "module"
10+
},
11+
"plugins": ["@typescript-eslint"]
12+
}

examples/postgresql/.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["assemblyscript-prettier"]
3+
}

examples/postgresql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Hypermode Functions Example using PostgreSQL database

examples/postgresql/asconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./node_modules/@hypermode/functions-as/plugin.asconfig.json",
3+
"options": {
4+
"transform": ["@hypermode/functions-as/transform", "json-as/transform"]
5+
}
6+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { postgresql } from "@hypermode/functions-as";
2+
3+
export function queryPeople(): string {
4+
return postgresql.query("neon", "select * from people", []);
5+
}
6+
7+
export function getPerson(name: string): string {
8+
const query = "select * from people where name = $1";
9+
return postgresql.query("neon", query, [name]);
10+
}
11+
12+
export function addPerson(
13+
name: string,
14+
age: i32,
15+
balance: f64,
16+
privkey: i8[],
17+
male: boolean,
18+
lat: f64,
19+
lon: f64,
20+
): void {
21+
const query =
22+
"insert into people (name, age, balance, privkey, created_at, male, home)" +
23+
" values ($1, $2, $3, $4, $5, $6, $7)";
24+
25+
postgresql.query("neon", query, [
26+
name,
27+
age.toString(),
28+
balance.toString(),
29+
privkey.toString(),
30+
new Date(Date.now()).toUTCString(),
31+
male.toString(),
32+
"(" + lat.toString() + "," + lon.toString() + ")",
33+
]);
34+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "assemblyscript/std/assembly.json",
3+
"include": ["./**/*.ts"]
4+
}

examples/postgresql/hypermode.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "https://manifest.hypermode.com/hypermode.json",
3+
"models": {
4+
// No models are used by this example, but if you add any, they would go here.
5+
},
6+
"hosts": {
7+
"neon": {
8+
"type": "postgresql",
9+
"connString": "postgresql://postgres:password@localhost:5432/data?sslmode=disable"
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)