Path: redb/redb.Tests.Integration/Tests/Sqlite/SqliteIndexCatalogTests.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/Sqlite/SqliteIndexCatalogTests.cs
----
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
using redb.Core.Data;
using redb.Core.Extensions;
using redb.Core.Models;
using redb.Core.Models.Configuration;
using redb.SQLite.Data;
using redb.SQLite.Extensions;
using redb.SQLite.Sql;
using redb.Tests.Integration.Fixtures;
using redb.Tests.Integration.Tests.Base;
namespace redb.Tests.Integration.Tests.Sqlite;
/// SqliteIndexCatalog.Base against a fresh SQLite file of this build (see ).
public class SqliteIndexCatalogTests : IndexCatalogTestsBase
{
private readonly Dictionary _files = new();
protected override Task CreateDatabaseAsync(string name)
{
SqliteDataSource.NativeExtensionPath ??= SqliteTestSupport.ResolveNativeExtension();
var path = Path.Combine(Path.GetTempPath(), name + ".db");
_files[name] = path;
return Task.FromResult($"Data Source={path}");
}
protected override Task DropDatabaseAsync(string name)
{
SqliteConnection.ClearAllPools();
if (_files.TryGetValue(name, out var path))
foreach (var file in new[] { path, path + "-wal", path + "-shm" })
{
try { if (File.Exists(file)) File.Delete(file); }
catch (IOException) { }
}
return Task.CompletedTask;
}
protected override void AddRedb(IServiceCollection services, string connectionString, Action configure)
=> services.AddRedb(o => o.UseSqlite(connectionString).Configure(configure));
protected override async Task> ReadCreateStatementsAsync(IRedbContext context)
{
var rows = await context.QueryAsync("SELECT name AS \"Name\", sql AS \"Sql\" FROM sqlite_master WHERE type = 'index' AND sql IS NOT NULL");
return rows.ToDictionary(r => r.Name!, r => r.Sql!, StringComparer.OrdinalIgnoreCase);
}
protected override IReadOnlyList Catalog => SqliteIndexCatalog.Base;
protected override (string File, string Namespace, string Class, string Member, RedbIndexOrigin Origin) Target =>
("redb.SQLite/sql/SqliteIndexCatalog.g.cs", "redb.SQLite.Sql", "SqliteIndexCatalog", "Base", RedbIndexOrigin.Base);
private sealed class SqlRow
{
public string? Name { get; set; }
public string? Sql { get; set; }
}
}