-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.ts
32 lines (27 loc) · 977 Bytes
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { remultExpress } from 'remult/remult-express'
import { Task } from '../shared/model.js'
import sqlite3 from 'sqlite3'
import { Sqlite3DataProvider } from 'remult/remult-sqlite3'
import { SqlDatabase, repo } from 'remult'
import { faker } from '@faker-js/faker'
export const entities = [Task]
export const api = remultExpress({
entities,
admin: true,
// dataProvider: new SqlDatabase(
// // Note that on stackblitz, this database name is only saved per user on their own browser.
// // To store the database on stackblitz, change the name not to include a dot on the start.
// new Sqlite3DataProvider(new sqlite3.Database('.database.sqlite'))
// ),
getUser: (req) => req.session!['user'],
initApi: async ()=>{
if(await repo(Task).count() === 0){
await repo(Task).insert(
Array.from({ length: 10 }).map((_, i) => ({
title: faker.hacker.phrase(),
completed: i % 2 === 0,
}))
)
}
}
})