Skip to content
Snippets Groups Projects
Commit 4da1d7e8 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: backend db from prototype

parent 204587ca
No related branches found
No related tags found
No related merge requests found
...@@ -127,4 +127,8 @@ dist ...@@ -127,4 +127,8 @@ dist
.yarn/unplugged .yarn/unplugged
.yarn/build-state.yml .yarn/build-state.yml
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
\ No newline at end of file
#===============================================================================
*.sqlite3
// Update with your config settings.
/**
* @type { Object.<string, import("knex").Knex.Config> }
*/
module.exports = {
development: {
client: "sqlite3",
connection: {
filename: "./dev.sqlite3",
},
},
// staging: {
// client: "postgresql",
// connection: {
// database: "my_db",
// user: "username",
// password: "password",
// },
// pool: {
// min: 2,
// max: 10,
// },
// migrations: {
// tableName: "knex_migrations",
// },
// },
// production: {
// client: "postgresql",
// connection: {
// database: "my_db",
// user: "username",
// password: "password",
// },
// pool: {
// min: 2,
// max: 10,
// },
// migrations: {
// tableName: "knex_migrations",
// },
// },
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema
.createTable("images", function (table) {
table.increments("id").primary();
table.string("filename", 200);
table.string("md5", 255);
table.binary("image");
})
.createTable("game_results", function (table) {
table.increments("id").primary();
table.string("transcription", 255);
table.integer("gametime", 11).notNullable();
table.integer("id_image", 11).notNullable();
table.foreign("id_image").references("id").inTable("images");
});
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropTable("game_results").dropTable("images");
};
This diff is collapsed.
...@@ -19,13 +19,15 @@ ...@@ -19,13 +19,15 @@
}, },
"dependencies": { "dependencies": {
"fastify": "^3.27.1", "fastify": "^3.27.1",
"fastify-cors": "^6.0.2" "fastify-cors": "^6.0.2",
"knex": "^1.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.3", "@types/jest": "^27.0.3",
"@types/node": "^16.11.11", "@types/node": "^16.11.11",
"@typescript-eslint/eslint-plugin": "^5.5.0", "@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0", "@typescript-eslint/parser": "^5.5.0",
"@vscode/sqlite3": "^5.0.7",
"eslint": "^8.3.0", "eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^25.3.0", "eslint-plugin-jest": "^25.3.0",
...@@ -34,6 +36,7 @@ ...@@ -34,6 +36,7 @@
"node-notifier": "^10.0.1", "node-notifier": "^10.0.1",
"nodemon": "^2.0.15", "nodemon": "^2.0.15",
"prettier": "^2.5.1", "prettier": "^2.5.1",
"sqlite3": "^5.0.2",
"ts-jest": "^27.0.7", "ts-jest": "^27.0.7",
"ts-node": "^10.5.0", "ts-node": "^10.5.0",
"typescript": "^4.5.2" "typescript": "^4.5.2"
......
import knex from "knex";
export const connection = knex({
client: "sqlite3", // or 'better-sqlite3'
connection: {
filename: "./mydb.sqlite",
// filename: ":memory:",
},
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment