import "reflect-metadata";
import { DataSource } from "typeorm";
import { Feed } from "./models/Feed.js";
import { User } from "./models/User.js";
import { Post } from "./models/Post.js";
import Logging from "./log.js";

export const AppDataSource = new DataSource({
   type: "sqlite",
   database: "persist/db.sqlite",
   logging: false,
   entities: [User, Feed, Post],
   subscribers: [],
   migrations: [],
})

export const appDataSourceReady = AppDataSource.initialize().then(() => {
   Logging.info("Database initialized!");
   return AppDataSource.synchronize().then(() => {
      Logging.info("Database synchronized!");
   })
}).catch((err) => {
   Logging.info("Database initialization failed!");
   Logging.error(err);
});