Nano.Data.SqLite
This package is part of the Nano Library, a set of reusable .NET libraries for building microservice applications. Nano addresses common non-business concerns such as logging, persistence, messaging, validation, and documentation, while remaining fully configurable and extensible, so applications can stay focused on business logic. See https://github.com/Nano-Core/Nano.Library for details.
Install
| Product | Versions |
|---|---|
| .NET |
README
Nano.Data.SqLite
SqLite data provider for Nano applications._
Table of Contents
Summary
Data Provider implementation for SqLite data access.
đź“– Learn more about Nano Data.
Try it out yourself using the Api.Data.SqLite, or Console.Data.SqLite example.
Registration
Install the Nano.Data.SqLite NuGet package.
dotnet add package Nano.Data.SqLite;
Register the SqLiteProvider provider during application startup in the ConfigureServices(...) method.
.ConfigureServices(services =>
{
services
.AddNanoData<SqLiteProvider, TContext>();
})
A BaseDbContext and BaseDbContextFactory must also be implemented and used as TContext, and also an initial migration added.
dotnet ef migrations add Initial --project {project-name}
Configuration
Add the data configuration to appsettings.json.
"Data": {
"BatchSize": 25,
"BulkBatchSize": 500,
"BulkBatchDelay": 1000,
"QueryRetryCount": 0,
"UseLazyLoading": false,
"StartupAction": "None",
"UseSensitiveDataLogging": false,
"QuerySplittingBehavior": "SingleQuery",
"DefaultCollation": null,
"ConnectionString": "Data Source=/data/nanoDb.sqlite",
"Repository": {
"UseAutoSave": false,
"QueryIncludeDepth": 4
},
"Identity": null,
"ConnectionPool": null,
"HealthCheck": {
"UnhealthyStatus": "Unhealthy"
}
}
...and appsettings.Development.json
"Data": {
"UseMigrateDatabase": true
}
Docker Compose
Add SqLite as a service dependency in docker-compose.yml.
services:
{service-name}:
volumes:
- ./bin/data:/data
Also the Dockerfile must have SqLite installed with spatial support. Add the following to both the Dockerfile and the Dockerfile.Local.
RUN apt-get update \
&& apt-get install -y libsqlite3-mod-spatialite \
&& apt-get install -y libspatialite-dev
Kubernetes
Add two additional kubernetes templates, storageclass.yaml and pvc.yaml, for dynamically manage and creating the disk for the SqLite database.
Also, update deployment.yaml adding the volumes and volume mounts.
spec:
template:
spec:
containers:
volumeMounts:
- name: %SERVICE_NAME%-volume
mountPath: /mnt/%STORAGE_SHARE_NAME%
volumes:
- name: %SERVICE_NAME%-volume
persistentVolumeClaim:
claimName: %SERVICE_NAME%-pvc
GitHub Actions
Add the following environment variables to the buid-and-deply.yml.
env:
DATA_NAME: nanoDb
DATA_SIZE: 10Gi
DATA_CONNECTIONSTRING: "Data Source=/data/{{ env.nanoDb }}.sqlite"
Additionally, this step has been added to ensure database migrations are applied.
- name: Database Migration
shell: pwsh
run: |
dotnet ef database update `
--no-build `
--startup-project $env:APP_NAME `
--connection "$env:DATA_MIGRATION_CONNECTIONSTRING" `;
if ($LastExitCode -ne 0)
{
throw "error";
};
Deployment commands must also be updated to apply each of the new Kubernetes templates.
Get-Content .kubernetes/{resource-name}.yaml `
| foreach { [Environment]::ExpandEnvironmentVariables($_) } `
| Set-Content .kubernetes/{resource-name}.tmp.yaml;
sudo kubectl apply -f .kubernetes/{resource-name}.tmp.yaml;
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.