SqLite data provider for Nano applications._
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.
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}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
}Add SqLite as a service dependency in docker-compose.yml.
services:
{service-name}:
volumes:
- ./bin/data:/dataAlso 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-devAdd 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%-pvcAdd 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;