mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
First steps for SQLite
This commit is contained in:
parent
29ec800996
commit
ebbf5ea21f
10 changed files with 231 additions and 29 deletions
39
NzbDrone.Core/Datastore/DbFactory.cs
Normal file
39
NzbDrone.Core/Datastore/DbFactory.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common;
|
||||
using ServiceStack.OrmLite;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
public interface IDbFactory
|
||||
{
|
||||
IDbConnection Create(string dbPath = null);
|
||||
}
|
||||
|
||||
public class DbFactory : IDbFactory
|
||||
{
|
||||
private readonly EnvironmentProvider _environmentProvider;
|
||||
|
||||
public DbFactory(EnvironmentProvider environmentProvider)
|
||||
{
|
||||
_environmentProvider = environmentProvider;
|
||||
}
|
||||
|
||||
public IDbConnection Create(string dbPath = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dbPath))
|
||||
{
|
||||
dbPath = _environmentProvider.GetObjectDbFolder();
|
||||
}
|
||||
|
||||
var dbFactory = new OrmLiteConnectionFactory(GetConnectionString(dbPath));
|
||||
return dbFactory.OpenDbConnection();
|
||||
}
|
||||
|
||||
private string GetConnectionString(string dbPath)
|
||||
{
|
||||
return String.Format("Data Source={0};Version=3;", dbPath);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue