sqlite3
main
Ajout de la base de données en Sqlite3 et des méthodes permettant de faire des actions sur la base de données.
"@sinclair/typebox": "^0.32.9",
"fastify": "^4.25.2",
"fastify": "^4.27.0",
"fastify-sqlite-typed": "^0.1.1",
This dependency is not used.
}
/* Fonction pour récupérer plusieurs lignes de la base de données */
function allDB(db: sqlite3.Database, query: string): Promise<any[]> {
-function allDB(db: sqlite3.Database, query: string): Promise<any[]> { +function allDB<T>(db: sqlite3.Database, query: string): Promise<T[]> { ``
db: sqlite3.Database,
query: string,
params: any[],
): Promise<void> {
-function getDB( +function getDB<T>( db: sqlite3.Database, query: string, params: any[], -): Promise<void> { +): Promise<T[]> {
/////////////////////////// Export des fonctions ///////////////////////////
export {
You can use the export keywork before each function declaration, instead of grouping them at the end of the file.
export
updateUserLogin,
updateUserPassword,
updateUserPermissions,
} from './database';
You may use a wildcard import here, it would reduce the size of the import:
import * as db from './database'; // ... db.createTables();
fastify.put<{
Params: { id: string };
Body: { newPermissions: number };
}>('/users/:id/permissions', async (request, reply) => {
-fastify.put<{ - Params: { id: string }; - Body: { newPermissions: number }; -}>('/users/:id/permissions', async (request, reply) => { +fastify.put('/users/:id/permissions', { + schema: { + params: Type.Object({ + id: Type.Number({ + minimum: 0 + }) + }), + body: Type.Object({ + newPermissions: Type.Number(), + }) + }, +}, async (request, reply) => {
Using TypeBox would allow Fastify to check the structure before it even reach your handler (and it will enforce numbers).
reply.send(user);
});
/* Route pour créer un language */
For now, let's not expose an REST API to manage languages.
b58317ae88
No due date set.
No dependencies set.
Deleting a branch is permanent. It CANNOT be undone. Continue?
Ajout de la base de données en Sqlite3 et des méthodes permettant de faire des actions sur la base de données.
"@sinclair/typebox": "^0.32.9",
"fastify": "^4.25.2",
"fastify": "^4.27.0",
"fastify-sqlite-typed": "^0.1.1",
This dependency is not used.
}
/* Fonction pour récupérer plusieurs lignes de la base de données */
function allDB(db: sqlite3.Database, query: string): Promise<any[]> {
db: sqlite3.Database,
query: string,
params: any[],
): Promise<void> {
}
/////////////////////////// Export des fonctions ///////////////////////////
export {
You can use the
export
keywork before each function declaration, instead of grouping them at the end of the file.updateUserLogin,
updateUserPassword,
updateUserPermissions,
} from './database';
You may use a wildcard import here, it would reduce the size of the import:
fastify.put<{
Params: { id: string };
Body: { newPermissions: number };
}>('/users/:id/permissions', async (request, reply) => {
Using TypeBox would allow Fastify to check the structure before it even reach your handler (and it will enforce numbers).
reply.send(user);
});
/* Route pour créer un language */
For now, let's not expose an REST API to manage languages.
b58317ae88
into main 11 months agoReviewers
b58317ae88
.