create new empty database if not exists
This commit is contained in:
parent
859e1e6554
commit
b3057362be
1 changed files with 30 additions and 0 deletions
30
Program.cs
30
Program.cs
|
@ -1,7 +1,9 @@
|
|||
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;
|
||||
|
@ -13,9 +15,37 @@ namespace BuecherwurmAPI
|
|||
{
|
||||
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 Books (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 =>
|
||||
|
|
Loading…
Reference in a new issue