feat(git-provider): Initial git registration storage in database
- update PostBuild.ps1 to not delete data directory created during debug - move sqlite-net-pcl to ModuleCore
This commit is contained in:
parent
caa65ca7c3
commit
633b35f7e9
5 changed files with 95 additions and 14 deletions
|
|
@ -1,4 +1,6 @@
|
|||
namespace ModuleCore.Database;
|
||||
using SQLite;
|
||||
|
||||
namespace ModuleCore.Database;
|
||||
|
||||
public class DatabaseManager
|
||||
{
|
||||
|
|
@ -16,8 +18,37 @@ public class DatabaseManager
|
|||
_databaseLocation = new FileInfo(Path.Combine(".", "data", $"{SanitiseFilename(databaseName)}.db"));
|
||||
|
||||
Directory.CreateDirectory(_databaseLocation.DirectoryName!);
|
||||
var file = File.Create(_databaseLocation.FullName);
|
||||
file.Close();
|
||||
|
||||
if (!File.Exists(_databaseLocation.FullName))
|
||||
{
|
||||
var file = File.Create(_databaseLocation.FullName);
|
||||
file.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void InConnection(Action<SQLiteConnection> dbAction)
|
||||
{
|
||||
using var conn = new SQLiteConnection(_databaseLocation.FullName);
|
||||
dbAction(conn);
|
||||
}
|
||||
|
||||
public T InConnection<T>(Func<SQLiteConnection, T> dbAction)
|
||||
{
|
||||
using var conn = new SQLiteConnection(_databaseLocation.FullName);
|
||||
return dbAction(conn);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a bool for the given query. Convenience method for <see cref="SQLiteConnection.ExecuteScalar"/>.
|
||||
/// </summary>
|
||||
/// <param name="query">A query starting with SELECT 1, optionally paramaterised with ?</param>
|
||||
/// <param name="args">Parameter values</param>
|
||||
/// <returns></returns>
|
||||
public bool Exists(string query, params object[] args)
|
||||
{
|
||||
using var conn = new SQLiteConnection(_databaseLocation.FullName);
|
||||
var exists = conn.ExecuteScalar<bool?>(query, args);
|
||||
return exists ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue