add segfaultapi functionality and use postgres

This commit is contained in:
2022-12-30 19:02:49 +02:00
parent daaca19af8
commit a846dd1e2d
48 changed files with 1576 additions and 377 deletions

74
src/lib/db.ts Normal file
View File

@@ -0,0 +1,74 @@
import { Sequelize, DataTypes } from "sequelize";
import config from "$lib/config";
import consola from "consola";
const sequelize = new Sequelize(config.db.url);
sequelize.define("Announcements", {
title: {
type: DataTypes.STRING,
allowNull: false
},
severity: {
type: DataTypes.STRING,
allowNull: false
},
author: {
type: DataTypes.STRING,
allowNull: false
},
link: {
type: DataTypes.STRING,
allowNull: true
},
created: {
type: DataTypes.BIGINT,
allowNull: false
}
});
sequelize.define("Posts", {
title: {
type: DataTypes.STRING,
allowNull: false
},
content: {
type: DataTypes.TEXT,
allowNull: false
},
tags: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: false
},
author: {
type: DataTypes.STRING,
allowNull: false
},
created: {
type: DataTypes.BIGINT,
allowNull: false
},
updated: {
type: DataTypes.BIGINT,
allowNull: true,
defaultValue: null
},
words: {
type: DataTypes.INTEGER,
allowNull: false
},
readingTime: {
type: DataTypes.INTEGER,
allowNull: false
}
});
try {
await sequelize.authenticate();
await sequelize.sync();
consola.success("Connected to Postgres");
} catch (error) {
consola.error("Failed to connect to Postgres:", error);
}
export default sequelize;