continued
implemented HTMX implemented ORM (sequelize)
This commit is contained in:
parent
2a9bd4e81b
commit
d756a192e4
71 changed files with 3822 additions and 694 deletions
41
lib/database/connect.mjs
Normal file
41
lib/database/connect.mjs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// models/index.js
|
||||
import { Sequelize } from 'sequelize';
|
||||
import { getConfig } from "../config.mjs";
|
||||
import { registerModels } from './models.mjs';
|
||||
|
||||
const configData = await getConfig();
|
||||
|
||||
// SQLite-Datenbank im data/-Verzeichnis
|
||||
const sequelize = new Sequelize({
|
||||
dialect: 'mysql',
|
||||
host: configData.database.host,
|
||||
port: configData.database.port,
|
||||
database: configData.database.database,
|
||||
username: configData.database.username,
|
||||
password: configData.database.password,
|
||||
logging: false,
|
||||
});
|
||||
|
||||
// Modelle initialisieren
|
||||
const {
|
||||
Group,
|
||||
User
|
||||
} = registerModels(sequelize);
|
||||
|
||||
// Datenbank synchronisieren
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('✓ MySQL connection successfull');
|
||||
// Automatische Migration
|
||||
await sequelize.sync({ alter: true, force: false });
|
||||
console.log('✓ MySQL migration finished');
|
||||
} catch (error) {
|
||||
console.error('✕ MySQL Error:', error);
|
||||
}
|
||||
})()
|
||||
|
||||
export {
|
||||
Group,
|
||||
User
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue