2013-02-04 01:01:36 +03:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using Eloquera.Client;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
|
|
{
|
|
|
|
public class EloqueraDbFactory
|
|
|
|
{
|
2013-02-04 03:10:15 +03:00
|
|
|
public EloqueraDb CreateMemoryDb()
|
2013-02-04 01:01:36 +03:00
|
|
|
{
|
2013-02-04 03:10:15 +03:00
|
|
|
return InternalCreate("server=(local);password=;options=inmemory;",Guid.NewGuid().ToString());
|
2013-02-04 01:01:36 +03:00
|
|
|
}
|
|
|
|
|
2013-02-04 03:10:15 +03:00
|
|
|
public EloqueraDb Create(string dbPath)
|
2013-02-04 01:01:36 +03:00
|
|
|
{
|
2013-02-04 03:10:15 +03:00
|
|
|
var file = new FileInfo(dbPath).Name;
|
|
|
|
return InternalCreate(string.Format("server=(local);database={0};usedatapath={1};password=;", file, dbPath),file);
|
|
|
|
}
|
2013-02-04 01:01:36 +03:00
|
|
|
|
2013-02-04 03:10:15 +03:00
|
|
|
private EloqueraDb InternalCreate(string connectionString, string databaseName)
|
|
|
|
{
|
|
|
|
var db = new DB(connectionString);
|
|
|
|
db.CreateDatabase(databaseName);
|
|
|
|
db.OpenDatabase(databaseName);
|
2013-02-04 01:01:36 +03:00
|
|
|
return new EloqueraDb(db);
|
|
|
|
}
|
2013-02-04 03:10:15 +03:00
|
|
|
|
|
|
|
|
2013-02-04 01:01:36 +03:00
|
|
|
}
|
|
|
|
}
|