- FireLance DatabaseConnection implementation - Crude test importing from GSMParser to FireLance DB.
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using Microsoft.Data.Sqlite;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Dapper;
|
|
using FireLance.Interfaces;
|
|
|
|
namespace GSMParser
|
|
{
|
|
public class DatabaseConnection : IDatabaseConnection
|
|
{
|
|
private SqliteConnection DBConnection = new SqliteConnection();
|
|
|
|
public void OpenConnection(string dbLocation, int port)
|
|
{
|
|
if (File.Exists(dbLocation) == false)
|
|
{
|
|
throw new FileNotFoundException(dbLocation);
|
|
}
|
|
|
|
DBConnection = new SqliteConnection($"Data Source={dbLocation};Mode=ReadOnly");
|
|
DBConnection.Open();
|
|
}
|
|
|
|
public void CloseCurrentConnection()
|
|
{
|
|
DBConnection.Close();
|
|
}
|
|
|
|
public bool IsConnectionOpen()
|
|
{
|
|
return Convert.ToBoolean(DBConnection.State);
|
|
}
|
|
|
|
public IEnumerable<IGameEntryModel> QueryGameById(string id)
|
|
{
|
|
return DBConnection.Query<GameEntryModel>(QueryBuilder.GameEntryByGameId(id), new DynamicParameters());
|
|
}
|
|
|
|
public IEnumerable<IDirectoriesModel> QueryDirectoryById(string id)
|
|
{
|
|
return DBConnection.Query<DirectoriesModel>(QueryBuilder.DirectoryByGameId(id), new DynamicParameters());
|
|
}
|
|
|
|
public IEnumerable<IGameEntryModel> QueryGameByName(string name)
|
|
{
|
|
return DBConnection.Query<GameEntryModel>(QueryBuilder.GameEntryByName(name), new DynamicParameters());
|
|
}
|
|
}
|
|
}
|