Sqlite.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Data;
  2. using System.Data.SQLite;
  3. using System.Threading.Tasks;
  4. namespace MediaBrowser.ServerApplication.Native
  5. {
  6. /// <summary>
  7. /// Class Sqlite
  8. /// </summary>
  9. public static class Sqlite
  10. {
  11. /// <summary>
  12. /// Connects to db.
  13. /// </summary>
  14. /// <param name="dbPath">The db path.</param>
  15. /// <returns>Task{IDbConnection}.</returns>
  16. /// <exception cref="System.ArgumentNullException">dbPath</exception>
  17. public static async Task<IDbConnection> OpenDatabase(string dbPath)
  18. {
  19. var connectionstr = new SQLiteConnectionStringBuilder
  20. {
  21. PageSize = 4096,
  22. CacheSize = 4096,
  23. SyncMode = SynchronizationModes.Normal,
  24. DataSource = dbPath,
  25. JournalMode = SQLiteJournalModeEnum.Wal
  26. };
  27. var connection = new SQLiteConnection(connectionstr.ConnectionString);
  28. await connection.OpenAsync().ConfigureAwait(false);
  29. return connection;
  30. }
  31. }
  32. }