aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/Native/Sqlite.cs
blob: cc20952d73e1c332482fac7338751dac63f2f854 (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
using System.Data;
using System.Data.SQLite;
using System.Threading.Tasks;

namespace MediaBrowser.ServerApplication.Native
{
    /// <summary>
    /// Class Sqlite
    /// </summary>
    public static class Sqlite
    {
        /// <summary>
        /// Connects to db.
        /// </summary>
        /// <param name="dbPath">The db path.</param>
        /// <returns>Task{IDbConnection}.</returns>
        /// <exception cref="System.ArgumentNullException">dbPath</exception>
        public static async Task<IDbConnection> OpenDatabase(string dbPath)
        {
            var connectionstr = new SQLiteConnectionStringBuilder
            {
                PageSize = 4096,
                CacheSize = 4096,
                SyncMode = SynchronizationModes.Normal,
                DataSource = dbPath,
                JournalMode = SQLiteJournalModeEnum.Wal
            };

            var connection = new SQLiteConnection(connectionstr.ConnectionString);

            await connection.OpenAsync().ConfigureAwait(false);

            return connection;
        }
    }
}