voile/Voile.Storage.Sqlite/SqliteDataStorageFactory.cs
2026-02-01 21:10:03 +01:00

42 lines
1.4 KiB
C#

using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Voile.Common.Reflection;
using Voile.Patchouli.Data;
using Voile.Patchouli.Reflection;
namespace Voile.Storage.Sqlite
{
[VoilePlugin]
[VoilePluginId(3)]
[Voile.Patchouli.Reflection.DisplayName("SQLite")]
[VoilePluginCanSaveFile(true,"SQLite3 Database (*.db)|*.db",CanSaveFileMode.SaveFile,false)]
public class SqliteDataStorageFactory : IVoileDataStorageFactory
{
public IVoileDataStorage CreateDataStorage()
{
if (string.IsNullOrEmpty(FilePath) || string.IsNullOrWhiteSpace(FilePath))
{
throw new ArgumentNullException(String.Format("{0} should not be empty.", nameof(FilePath)));
}
if (scsb == null)
{
scsb = new SqliteConnectionStringBuilder();
scsb.DataSource = FilePath;
scsb.Mode = SqliteOpenMode.ReadWriteCreate;
scsb.Pooling = true;
}
return new SqliteDataStorage(scsb);
}
[Description("The path to the SQLite database file. If it doesn't exist, it will be created")]
public string FilePath { get; set; }
private SqliteConnectionStringBuilder scsb;
}
}