Compare commits

...

6 Commits

Author SHA1 Message Date
baz e2d3881cce Create dbInit 2023-12-16 20:38:58 +00:00
baz 1519c85f27 Create BeatenGames sequelize module 2023-12-16 20:38:46 +00:00
baz e80dfdf953 Create Games sequelize module 2023-12-16 20:38:07 +00:00
baz 78cd678f6f Create Users sequelize module 2023-12-16 20:38:00 +00:00
baz 3fe6b11765 Simplify getCoverURL then 2023-12-16 20:37:09 +00:00
baz 68ad62dcba Correct .gitignore 2023-12-16 20:36:35 +00:00
6 changed files with 66 additions and 4 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
node_modules
.env
config.json
.sqlite
*.sqlite

20
dbInit.js Normal file
View File

@ -0,0 +1,20 @@
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
storage: 'database.sqlite',
});
const db = require('./models/games.js')(sequelize, Sequelize.DataTypes);
require('./models/users.js')(sequelize, Sequelize.DataTypes);
require('models/beatenGames.js')(sequelize, Sequelize.DataTypes);
const force = process.argv.includes('--force') || process.argv.includes('-f');
sequelize.sync({ force }).then(async () => {
// await Promise.all();
console.log('Database synced');
sequelize.close();
}).catch(console.error);

View File

@ -17,9 +17,7 @@ async function getCoverURL(id) {
url = 'https:'.concat(response[0].url);
}
})
.then(response => {
url = url.replace('t_thumb', 't_1080p_2x');
})
.then(url = url.replace('t_thumb', 't_1080p_2x'))
.catch(err => {
console.error(err);
});

16
models/beatenGames.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = (sequelize, DataTypes) => {
return sequelize.define('beatenGames', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
user_id: DataTypes.INTEGER,
game_id: DataTypes.STRING,
date_created: DataTypes.DATE,
date_last_modified: DataTypes.DATE,
}, {
timestamps: false,
});
};

14
models/games.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = (sequelize, DataTypes) => {
return sequelize.define('games', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
unique: false,
},
}, {
timestamps: false,
});
};

14
models/users.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = (sequelize, DataTypes) => {
return sequelize.define('users', {
user_id: {
type: DataTypes.STRING,
primaryKey: true,
},
username: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
timestamps: false,
});
};