Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/postgresql/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"env": {
"es6": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"]
}
3 changes: 3 additions & 0 deletions examples/postgresql/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["assemblyscript-prettier"]
}
1 change: 1 addition & 0 deletions examples/postgresql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Hypermode Functions Example using PostgreSQL database
6 changes: 6 additions & 0 deletions examples/postgresql/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./node_modules/@hypermode/functions-as/plugin.asconfig.json",
"options": {
"transform": ["@hypermode/functions-as/transform", "json-as/transform"]
}
}
40 changes: 40 additions & 0 deletions examples/postgresql/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { postgresql } from "@hypermode/functions-as";

class Person {
ID: i64 = 0;
name!: string;
age!: i64;
home!: postgresql.Point;
}

export function queryPeople(): Person[] {
const resp = postgresql.query<Person>(
"neon",
"select name, age, home from people",
);
return resp.rows;
}

export function getPerson(name: string): Person | null {
const query = "select age, home from people where name = $1";

const params: postgresql.Params = new postgresql.Params();
params.push(name);

const people = postgresql.query<Person>("neon", query, params);
return people.rows[0];
}

export function addPerson(name: string, age: i32, lat: f64, lon: f64): void {
const query =
"insert into people (name, age, home) values ($1, $2, $3) RETURNING id";

const params: postgresql.Params = new postgresql.Params();
params.push(name);
params.push(age);
params.push(new postgresql.Point(lat, lon));

// TODO
const people = postgresql.query<Person>("neon", query, params);
const person = people.rows[0];
}
4 changes: 4 additions & 0 deletions examples/postgresql/assembly/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "assemblyscript/std/assembly.json",
"include": ["./**/*.ts"]
}
12 changes: 12 additions & 0 deletions examples/postgresql/hypermode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://manifest.hypermode.com/hypermode.json",
"models": {
// No models are used by this example, but if you add any, they would go here.
},
"hosts": {
"neon": {
"type": "postgresql",
"connString": "postgresql://postgres:password@localhost:5432/data?sslmode=disable"
}
}
}
Loading