rsnext/examples/with-postgres/lib/todos.ts
Steven 4466ba436b
chore(examples): use default prettier for examples/templates (#60530)
## Description
This PR ensures that the default prettier config is used for examples
and templates.

This config is compatible with `prettier@3` as well (upgrading prettier
is bigger change that can be a future PR).

## Changes
- Updated `.prettierrc.json` in root with `"trailingComma": "es5"` (will
be needed upgrading to prettier@3)
- Added `examples/.prettierrc.json` with default config (this will
change every example)
- Added `packages/create-next-app/templates/.prettierrc.json` with
default config (this will change every template)

## Related

- Fixes #54402
- Closes #54409
2024-01-11 16:01:44 -07:00

35 lines
707 B
TypeScript

import sql from "./db";
export interface ToDo {
id: number;
text: string;
done: boolean;
}
export async function list() {
return await sql<ToDo[]>`
SELECT id, text, done FROM todos
ORDER BY id
`;
}
export async function create(todo: ToDo) {
return await sql<ToDo[]>`
INSERT INTO todos (text, done) VALUES (${todo.text}, false)
RETURNING id, text, done
`;
}
export async function update(todo: ToDo) {
return await sql<ToDo[]>`
UPDATE todos SET done=${todo.done} WHERE id=${todo.id}
RETURNING id, text, done
`;
}
export async function remove(todo: ToDo) {
return await sql<ToDo[]>`
DELETE FROM todos WHERE id=${todo.id}
RETURNING id, text, done
`;
}