Use MySQL
Add MySQL as a database with the @primate/mysql module. Configure it in
config/db; Primate connects to it and provides a unified API.
Ensure MySQL is running and accessible.
$ npm install @primate/mysql```
---
### 2) Configure
Create a database configuration file.
<div class="tabbed"><span class="captionline">
<span class="captions"><span class='active'> TypeScript</span></span><span class="filenames"><span class='active'>config/db/index.ts</span></span></span><span class="tabs"><div>
```ts
import mysql from "@primate/mysql";
export default mysql({
host: "localhost",
port: 3306,
database: "app",
// username: "user",
// password: "pass",
});
TypeScriptstores/User.ts
import p from "pema";
import key from "primate/orm/key";
import store from "primate/orm/store";
import db from "../config/db/index.ts";
export default store({
name: "user",
db,
schema: {
id: key.primary(p.uuid),
name: p.string,
email: p.string.email(),
},
});
TypeScriptroutes/users.ts
import User from "#store/User";
import route from "primate/route";
route.get(async () => {
const users = await User.find({});
return users;
});
route.post(async request => {
const user = await User.insert(request.body);
return user;
});