From 23f39dae857481bd946c4cf5ea69db5b5d751204 Mon Sep 17 00:00:00 2001
From: SkajpCZ <103284636+SkajpCZ@users.noreply.github.com>
Date: Mon, 3 Nov 2025 12:21:01 +0100
Subject: [PATCH] feat: basic DB setup
---
.gitignore | 2 ++
Database.cs | 10 +++++++---
Knihovna.csproj | 5 ++++-
Program.cs | 40 +++++++++++++++++++++++++++++++++++++++-
src/Something.cs | 0
5 files changed, 52 insertions(+), 5 deletions(-)
delete mode 100644 src/Something.cs
diff --git a/.gitignore b/.gitignore
index b5d7fe6..0737f04 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+*.sqlite
+*.sln
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
diff --git a/Database.cs b/Database.cs
index d30abd9..e9a4509 100644
--- a/Database.cs
+++ b/Database.cs
@@ -1,12 +1,13 @@
using System.Data;
+using Microsoft.Data.Sqlite;
namespace Database
{
public class Database
{
- public static void CreateDatabaseQuery()
+ public static void CreateDatabaseQuery(SqliteConnection conn)
{
- string createTableQuery = @"
+ string createTableQuery = @"
CREATE TABLE [Books] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT,
[Name] TEXT NOT NULL,
@@ -21,7 +22,7 @@ namespace Database
[ID] INTEGER PRIMARY KEY AUTOINCREMENT,
[Name] TEXT,
[Surname] TEXT,
- [DateOfBirth] DATE,
+ [DateOfBirth] DATE
);
CREATE TABLE [Publisher] (
[ID] INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -43,6 +44,9 @@ namespace Database
[Name] TEXT,
[Surname] TEXT
);";
+ var command = conn.CreateCommand();
+ command.CommandText = createTableQuery;
+ command.ExecuteNonQuery();
}
}
}
\ No newline at end of file
diff --git a/Knihovna.csproj b/Knihovna.csproj
index d6cb315..7385a14 100644
--- a/Knihovna.csproj
+++ b/Knihovna.csproj
@@ -8,7 +8,10 @@
-
+
+
+
+
diff --git a/Program.cs b/Program.cs
index 5f28270..f0f70ae 100644
--- a/Program.cs
+++ b/Program.cs
@@ -1 +1,39 @@
-
\ No newline at end of file
+using System;
+using Microsoft.Data.Sqlite;
+using Database;
+
+public class Program
+{
+ public static void Main()
+ {
+ string db = "Database.sqlite";
+ string connectionString = "Data Source=" + db;
+
+ try
+ {
+ using (var connection = new SqliteConnection(connectionString))
+ {
+ connection.Open();
+ try
+ {
+ Database.Database.CreateDatabaseQuery(connection);
+ }
+ catch
+ {
+ Console.WriteLine("Database already exists.");
+ }
+
+
+ using (var command = connection.CreateCommand())
+ {
+ // implment stuff here idc
+ }
+
+ }
+ }
+ catch (SqliteException ex)
+ {
+ Console.WriteLine($"{ex.Source}: {ex.Message}");
+ }
+ }
+}
diff --git a/src/Something.cs b/src/Something.cs
deleted file mode 100644
index e69de29..0000000