Use SurrealDB
Add SurrealDB as a database with the @primate/surrealdb
module. Configure it
in config/database
; Primate connects to it and provides a unified API.
Ensure SurrealDB is running and accessible. Primate will otherwise default to
the ephemeral in-memory database.
npm install @primate/surrealdb
import surrealdb from "@primate/surrealdb";
export default surrealdb({
database: "app",
host: "localhost",
port: 8000,
// username: "user",
// password: "pass",
});
// stores/User.ts
import store from "primate/store";
import primary from "pema/primary";
import string from "pema/string";
export default store({
id: primary,
name: string,
email: string,
});
// routes/users.ts
import route from "primate/route";
import User from "#store/User";
route.get(async () => {
const users = await User.find({});
return users;
});
route.post(async (request) => {
const user = await User.insert(request.body);
return user;
});