deno.land / x / abc@v1.3.3 / examples / ultra_cat_app / cat / group.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import type { Group } from "../deps.ts";import type { Cat } from "./cat.ts";
import DB from "../db.ts";
export default function (g: Group) { g.get("", (c) => { const cats = DB.query(`select * from cats`);
return cats; }) .post("", async (c) => { const { name, age } = await c.body as Cat;
if (name && age) { const result = await DB.execute( `INSERT INTO cats(name, age) VALUES(?, ?)`, [name, age], );
if (result.affectedRows === 1) { return { id: result.lastInsertId, name, age }; } } }) .delete("/:id", async (c) => { const id = Number(c.params.id);
if (id) { const result = await DB.execute(`DELETE FROM cats WHERE id = ?`, [id]);
return result; } }) .put("/:id", async (c) => { const id = Number(c.params.id); const { name, age } = await c.body as Cat;
if (id) { const result = await DB.execute( `UPDATE cats SET name = ?, age = ? where id = ?`, [name, age, id], );
return result; } });}
abc

Version Info

Tagged at
4 years ago