mirror of
https://github.com/Ratstail91/sineQL.git
synced 2025-11-29 10:44:28 +11:00
Moved to using a real database ORM for testing
This commit is contained in:
12
test/database/index.js
Normal file
12
test/database/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, {
|
||||
host: process.env.DB_HOSTNAME,
|
||||
dialect: 'mariadb',
|
||||
timezone: process.env.DB_TIMEZONE,
|
||||
logging: process.env.DB_LOGGING ? console.log : false
|
||||
});
|
||||
|
||||
sequelize.sync();
|
||||
|
||||
module.exports = sequelize;
|
||||
16
test/database/models/authors.js
Normal file
16
test/database/models/authors.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const Sequelize = require('sequelize');
|
||||
const sequelize = require('..');
|
||||
|
||||
module.exports = sequelize.define('authors', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER(11),
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
unique: true
|
||||
},
|
||||
|
||||
name: {
|
||||
type: Sequelize.TEXT
|
||||
}
|
||||
});
|
||||
24
test/database/models/books.js
Normal file
24
test/database/models/books.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const Sequelize = require('sequelize');
|
||||
const sequelize = require('..');
|
||||
|
||||
module.exports = sequelize.define('books', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER(11),
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
unique: true
|
||||
},
|
||||
|
||||
title: {
|
||||
type: Sequelize.TEXT
|
||||
},
|
||||
|
||||
published: {
|
||||
type: Sequelize.TEXT
|
||||
},
|
||||
|
||||
rating: {
|
||||
type: Sequelize.FLOAT
|
||||
}
|
||||
});
|
||||
12
test/database/models/index.js
Normal file
12
test/database/models/index.js
Normal file
@@ -0,0 +1,12 @@
|
||||
const sequelize = require('..');
|
||||
const authors = require('./authors');
|
||||
const books = require('./books');
|
||||
|
||||
books.belongsTo(authors, { as: 'author' }); //books now reference the authorId
|
||||
|
||||
sequelize.sync();
|
||||
|
||||
module.exports = {
|
||||
authors,
|
||||
books
|
||||
};
|
||||
Reference in New Issue
Block a user