blob: bd70cff6cf1688aedf9c70d213c1d76f4adb9512 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
using System;
using System.Data;
using System.Threading.Tasks;
using MediaBrowser.Model.Logging;
using Emby.Server.Core.Data;
using Microsoft.Data.Sqlite;
namespace Emby.Server.Data
{
public class DbConnector : IDbConnector
{
private readonly ILogger _logger;
public DbConnector(ILogger logger)
{
_logger = logger;
}
public async Task<IDbConnection> Connect(string dbPath, bool isReadOnly, bool enablePooling = false, int? cacheSize = null)
{
if (string.IsNullOrEmpty(dbPath))
{
throw new ArgumentNullException("dbPath");
}
//SQLiteConnection.SetMemoryStatus(false);
var connectionstr = new SqliteConnectionStringBuilder
{
//PageSize = 4096,
//CacheSize = cacheSize ?? 2000,
//SyncMode = SynchronizationModes.Normal,
DataSource = dbPath,
//JournalMode = SQLiteJournalModeEnum.Wal,
// This is causing crashing under linux
//Pooling = enablePooling && Environment.OSVersion.Platform == PlatformID.Win32NT,
//ReadOnly = isReadOnly,
Cache = enablePooling ? SqliteCacheMode.Default : SqliteCacheMode.Private,
Mode = isReadOnly ? SqliteOpenMode.ReadOnly : SqliteOpenMode.ReadWriteCreate
};
var connectionString = connectionstr.ConnectionString;
var connection = new SqliteConnection(connectionString);
await connection.OpenAsync().ConfigureAwait(false);
return connection;
}
}
}
|