-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update SQLite readme. Add SQLite to nuget tests
- Loading branch information
1 parent
7bd61f4
commit 14d04c6
Showing
8 changed files
with
185 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# KeyValueRepo.SQLite | ||
[![.github/workflows/dev-ci-sql-lite.yml](https://github.com/calebjenkins/KeyValueRepo/actions/workflows/dev-ci-sql-lite.yml/badge.svg?branch=develop)](https://github.com/calebjenkins/KeyValueRepo/actions/workflows/dev-ci.yml) | ||
[![.github/workflows/main-publish-sql-lite.yml](https://github.com/calebjenkins/KeyValueRepo/actions/workflows/main-publish.yml/badge.svg?branch=main)](https://github.com/calebjenkins/KeyValueRepo/actions/workflows/main-publish-sql-lite.yml) | ||
[![NuGet](https://img.shields.io/nuget/dt/calebs.keyvaluerepo.svg)](https://www.nuget.org/packages/Calebs.KeyValueRepo.SQLite) | ||
[![NuGet](https://img.shields.io/nuget/vpre/calebs.keyvaluerepo.svg)](https://www.nuget.org/packages/Calebs.KeyValueRepo.SQLite) | ||
[![.github/workflows/working-branches.yml](https://github.com/calebjenkins/KeyValueRepo/actions/workflows/working-branches.yml/badge.svg)](https://github.com/calebjenkins/KeyValueRepo/actions/workflows/working-branches.yml) | ||
|
||
A SqlLite implementation of a generic the KeyValueRepo interface for Key Value storage operations. Ideal for simple key-values that might migrate to SQL Server or NoSQL - a quick and easy way to create a KeyValue store. | ||
|
||
By default, this library ships with an in-memory implementation. `KeyValueInMemory` which implements the `IKeyValueRepo` interface. | ||
|
||
## Installing KeyValueRepo | ||
|
||
You should install [Extensions with NuGet](https://www.nuget.org/packages/Calebs.KeyValueRepo.SQLite): | ||
|
||
Install-Package Calebs.KeyValueRepo.SQLite | ||
|
||
Or via the .NET Core command line interface: | ||
|
||
dotnet add package Calebs.KeyValueRepo.SQLite | ||
|
||
Either command, from Package Manager Console or .NET Core CLI, will download and install Calebs.KeyValueRepo and all required dependencies. | ||
|
||
## Contributing | ||
- PRs should be against the `Develop` branch. | ||
- Merged PRs to `Develop` will trigger a `[version]-ci-[buildnumber]` deployment to nuget, assuming all unit tests pass. | ||
- Merged PRs to `Main` will trigger a [version] deployment to nuget, assuming all of the tests pass. | ||
|
||
## Versioning | ||
The package `version` is defined in the `KeyValueSqlLiteRepo.csproj` file, using .NET SDK style structure. We follow `semantic versioning` for this package. Implementations should match Major releases with KeyValueRepo package. | ||
|
||
|
||
## Methods in IKeyValueRepo | ||
|
||
- Get<T>(string Id) | ||
- Get<T>(int Id) => Get<T>(string Id) | ||
- Note: This method has a _default implementation_ that performs a `ToString()` on the Id and calls the `Get<T>(string Id)` method. | ||
- GetAll<T>() | ||
- Update<T>(string Id, T object) | ||
- Update<T>(int Id, T object) => Update(string Id, T object) | ||
- Note This method has a _default implementation_ that performs a `ToSTring()` on the int Id and calls the `Update<T>(string Id, T object)` method. | ||
|
||
|
||
## Release History & Development Goals | ||
- 0.1.0 - initial release (in Memory) | ||
- 0.2.0 - added SqlLite Implementation | ||
- ✔ SQLite [Nuget Package](https://www.nuget.org/packages/Calebs.KeyValueRepo.SQLite/) | ||
### Future Goals | ||
--- | ||
- New Feature: KV Meta Objects | ||
- New Repo: Sql Server Implementation | ||
- New Repo: Azure Tables Implementation | ||
- New Repo: Azure CosmoDB Implementation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
| ||
|
||
namespace KeyValueRepoTests; | ||
|
||
[Collection ("RepoTests")] | ||
public class SqLiteTests : InMemeoryTests | ||
{ | ||
ILogger<KeyValueSqLiteRepo> _logger = new Mock<ILogger<KeyValueSqLiteRepo>>().Object; | ||
ILogger<SchemaValidator> _schemaLogger = new Mock<ILogger<SchemaValidator>>().Object; | ||
ITestOutputHelper _out; | ||
|
||
public SqLiteTests(ITestOutputHelper output) | ||
{ | ||
_out = output ?? throw new ArgumentNullException(nameof(output)); | ||
} | ||
|
||
public IKeyValueRepo GetNewRepo(string path) | ||
{ | ||
var opt = new KeyValueSqlLiteOptions() | ||
{ | ||
ConnectionString = path, | ||
ColumnPrefix = "col" | ||
}; | ||
var validator = new SchemaValidator(_schemaLogger); | ||
return new KeyValueSqLiteRepo(_logger, validator, opt); | ||
} | ||
public override IKeyValueRepo GetNewRepo() | ||
{ | ||
return GetNewRepo("Data Source=./Db.db"); | ||
} | ||
|
||
[Fact] | ||
public void ShouldBeAbleToInstanciate() | ||
{ | ||
var db = GetNewRepo(); | ||
db.Should().NotBeNull(); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCreateDbInstance() | ||
{ | ||
var db = GetNewRepo(); | ||
var result = await db.AsKeyValueSqlLiteRepo().ValidateSchema(); | ||
result.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void FileNameIsAvailable() | ||
{ | ||
var db = GetNewRepo(); | ||
var filepath = db.AsKeyValueSqlLiteRepo().DatabaseFileName; | ||
filepath.Should().Contain("Db.db"); | ||
} | ||
|
||
[Fact] | ||
public async Task CorrectFileGetsCreated() | ||
{ | ||
var db = GetNewRepo(); | ||
var filePath = db.AsKeyValueSqlLiteRepo().DatabaseFileName; | ||
|
||
// Clear File | ||
await removeDbFileIfExists(db.AsKeyValueSqlLiteRepo()); | ||
|
||
// Create a new File | ||
var valid = await db.AsKeyValueSqlLiteRepo().ValidateSchema(); | ||
File.Exists(filePath).Should().BeTrue(); | ||
|
||
// Clean Up | ||
await removeDbFileIfExists(db.AsKeyValueSqlLiteRepo()); | ||
} | ||
|
||
private async Task removeDbFileIfExists(KeyValueSqLiteRepo Repo) | ||
{ | ||
var filePath = Repo.DatabaseFileName; | ||
Debug.WriteLine($"Database path: {filePath}"); | ||
|
||
var exists = File.Exists(filePath); | ||
|
||
if (exists) | ||
{ | ||
await Repo.ReleaseForCleanUp(); | ||
File.Delete(filePath); | ||
File.Exists(filePath).Should().BeFalse(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task ConfirmTableDoesNotExistAndCanBeCreated() | ||
{ | ||
var tmpData = Guid.NewGuid().ToString().Substring(0, 5); | ||
var db = GetNewRepo($"Data Source=./{tmpData}.db"); | ||
var filePath = db.AsKeyValueSqlLiteRepo().DatabaseFileName; | ||
|
||
// Reset DB | ||
await removeDbFileIfExists(db.AsKeyValueSqlLiteRepo()); | ||
|
||
var opt = new KeyValueSqlLiteOptions() { ColumnPrefix = "col" }; | ||
var defaultTableName = opt.DefaultTableName; | ||
|
||
ILogger<SchemaValidator> _SchemaLogger = new Mock<ILogger<SchemaValidator>>().Object; | ||
|
||
var verify = new SchemaValidator(_SchemaLogger); | ||
bool exist = await verify.TablesExists(defaultTableName, db.AsKeyValueSqlLiteRepo().DbConn); | ||
exist.Should().BeFalse(); | ||
|
||
bool tableCreated = await verify.CreateAllTables(opt, db.AsKeyValueSqlLiteRepo().DbConn); | ||
tableCreated.Should().BeTrue(); | ||
|
||
exist = await verify.TablesExists(defaultTableName, db.AsKeyValueSqlLiteRepo().DbConn); | ||
exist.Should().BeTrue(); | ||
|
||
var IsValid = await verify.ValidateSchema(opt, db.AsKeyValueSqlLiteRepo().DbConn); | ||
IsValid.HasError.Should().BeFalse(); | ||
IsValid.Messages.Count.Should().Be(7); | ||
|
||
// Reset DB | ||
await removeDbFileIfExists(db.AsKeyValueSqlLiteRepo()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters