57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Data.Sqlite;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace BuecherwurmAPI
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
if (!File.Exists("LongWormMemory.db"))
|
|
{
|
|
CreateNewEmptyDB();
|
|
MakeImports();
|
|
}
|
|
CreateHostBuilder(args).Build().Run();
|
|
}
|
|
|
|
private static void MakeImports()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static void CreateNewEmptyDB()
|
|
{
|
|
File.Create("LongWormMemory.db");
|
|
var connectionBuilder = new SqliteConnectionStringBuilder {DataSource = "LongWormMemory.db"};
|
|
var connection = new SqliteConnection(connectionBuilder.ConnectionString);
|
|
connection.Open();
|
|
using (var command = connection.CreateCommand())
|
|
{
|
|
command.CommandText = "CREATE TABLE Lends (Id INTEGER NOT NULL PRIMARY KEY, ItemId INTEGER NOT NULL, ReturnDate TEXT NOT NULL, Customer TEXT NOT NULL, Returned INTEGER NOT NULL)";
|
|
command.ExecuteNonQuery();
|
|
command.CommandText = "CREATE TABLE Items (ItemId INTEGER NOT NULL PRIMARY KEY, BookId INTEGER NOT NULL)";
|
|
command.ExecuteNonQuery();
|
|
command.CommandText = "CREATE TABLE Products (ProductId INTEGER PRIMARY KEY, Name TEXT, Author TEXT, Country TEXT, Link TEXT, Language TEXT, Pages INTEGER, Year INTEGER, Category INTEGER, ImageLink TEXT, LendTime INTEGER, LendType INTEGER)";
|
|
command.ExecuteNonQuery();
|
|
}
|
|
}
|
|
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
}
|
|
}
|