magic.data.cql
14.5.7
dotnet add package magic.data.cql --version 14.5.7
NuGet\Install-Package magic.data.cql -Version 14.5.7
<PackageReference Include="magic.data.cql" Version="14.5.7" />
paket add magic.data.cql --version 14.5.7
#r "nuget: magic.data.cql, 14.5.7"
// Install magic.data.cql as a Cake Addin #addin nuget:?package=magic.data.cql&version=14.5.7 // Install magic.data.cql as a Cake Tool #tool nuget:?package=magic.data.cql&version=14.5.7
NoSQL based IO, caching, and logging adapters for Hyperlambda
This project contains alternative NoSQL file system services, implementing IFileService
, IFolderService
, and
IStreamService
, allowing you to use it as an interchangeable "virtual file system" for cases where you want
to have 100% stateless magic instances. This is important if you're using Magic in a Kubernetes cluster or
something similar, load balancing invocations, virtually resolving files and folders towards a virtual file system.
If you take this path you'll have to configure your "appsettings.json" file such as illustrated further
down in this document. The project also contains an ILogger
implementation service you can use that will create
log entries in a NoSQL based storage of your choice, in addition to an IMagicCache
implementation service
allowing you to use a NoSQL based out of process cache implementation. See further down in this document for
details about how to configure these parts.
Configuration
The primary configuration for the project to apply for your "appsettings.json" file can be found below. Notice,
although you can create as many NoSQL cluster connection settings as you wish, and use these in your own code,
the IO, caching, and logging services requires you to use generic
as your cluster name, and you cannot change
this.
{
"magic": {
"cql": {
"generic": {
"host": "127.0.0.1",
"credentials": {
"username": "xxx",
"password": "xxx"
},
"port": 12345
}
}
}
}
Notice - The "credentials" parts above are optional, and can be ommitted if you don't require authentication to connect to your database. You can also provide multiple hosts as contact points, by separating multiple IP addresses or hosts by a comma (,). The above "port" parts is also optional.
The above configures the adapter to use 127.0.0.1
as the host for your contact point or cluster. To configure
the adapter to store files and folders inside of its CQL based database, you can alternatively add something such
as follows to your "appsettings.json" file.
{
"magic": {
"io": {
"file-service": "magic.data.cql.io.CqlFileService",
"folder-service": "magic.data.cql.io.CqlFolderService",
"stream-service": "magic.data.cql.io.CqlStreamService"
}
}
}
Notice - This project also includes a "mixed" service implementation, storing system files and folders in the file system while storing dynamic files and folders in a NoSQL database of your choice. These can be found in the same namespace, but are named "MixedXXX" instead of using the above names.
If you want to use a CQL based log implementation, you'll have to configure Magic to use the NoSQL
ILogger
service such as follows.
{
"magic": {
"logging": {
"service": "magic.data.cql.logging.Logger"
}
}
}
If you want to use a CQL based caching implementation, you'll have to configure Magic to use the NoSQL
IMagicCache
service such as follows.
{
"magic": {
"caching": {
"service": "magic.data.cql.caching.Caching"
}
}
}
Schemas
To use the alternative CQL based file storage system you'll have to create your "magic_files" keyspace and its "files" table as follows.
create keyspace if not exists magic_files with replication = { 'class': 'NetworkTopologyStrategy', 'replication_factor': 5 };
use magic_files;
create table if not exists files(
tenant text,
cloudlet text,
folder text,
filename text,
content blob,
primary key((tenant, cloudlet), folder, filename));
To use the alternative CQL based logging implementation you'll have to create your "magic_log" keyspace and its "log" table as follows.
create keyspace if not exists magic_log with replication = { 'class': 'NetworkTopologyStrategy', 'replication_factor': 3 };
use magic_log;
create table if not exists log(
tenant text,
cloudlet text,
created timeuuid,
type text,
content text,
exception text,
meta frozen<map<text, text>>,
primary key((tenant, cloudlet), created)) with clustering order by (created desc);
alter table log with default_time_to_live = 1209600;
Notice - The above setting for TTL implies log items will be automatically evicted after 14 days, since 1,209,600 seconds implies 14 days. Depending upon your needs you might want to increase or decrease this setting. However, to avoid exhausting your hard drive space over time on your server, we suggest you do not entirely remove the TTL setting.
To use the alternative CQL based caching implementation you'll have to create your "magic_cache" keyspace and its "cache" table as follows.
create keyspace if not exists magic_cache with replication = { 'class': 'NetworkTopologyStrategy', 'replication_factor': 3 };
use magic_cache;
create table if not exists cache(
tenant text,
cloudlet text,
key text,
value text,
primary key((tenant, cloudlet), key));
Adding existing files into NoSQL database
The following Hyperlambda will insert all your existing files and folders into your cluster keyspace, allowing you to
play around with an existing CQL file system implementation. Notice, you'll have to change the [.tenant] and
[.cloudlet] values to resemble the absolute root folder for your Magic backend. The values in the file below is
obviously just an example of how it might look like if you've got the files on a Mac within your "Documents" folder.
The "tenant" and the "cloudlet" parts are resolved by doing a string split operation on your magic:io:root-files
root folder upon the last (/) found in your folder - Implying if you use the Docker images with the default configuration
the "tenant" part would become "magic" and the "cloudlet" part would become "files", since the Docker images
stores files within the "/magic/files/" folder.
/*
* Inserts all dynamic files and folders into the magic CQL database.
*/
cql.connect:[generic|magic_files]
/*
* The root folder where your Magic backend is running.
*/
.tenant:Users
.cloudlet:"thomashansen/Documents/projects/magic/magic/backend"
/*
* Inserting root folder.
*/
cql.execute:"insert into files (tenant, cloudlet, folder, filename) values (:tenant, :cloudlet, '/files/', '')"
tenant:x:@.tenant
cloudlet:x:@.cloudlet
/*
* Inserting appsettings.json and its folder.
*/
config.load
convert:x:-
type:bytes
cql.execute:"insert into files (tenant, cloudlet, folder, filename, content) values (:tenant, :cloudlet, '/config/', 'appsettings.json', :config)"
tenant:x:@.tenant
cloudlet:x:@.cloudlet
config:x:@convert
cql.execute:"insert into files (tenant, cloudlet, folder, filename) values (:tenant, :cloudlet, '/config/', '')"
tenant:x:@.tenant
cloudlet:x:@.cloudlet
/*
* Inserting folders.
*/
io.folder.list-recursively:/
display-hidden:true
for-each:x:-/*
strings.concat
.:/files
get-value:x:@.dp/#
cql.execute:"insert into files (tenant, cloudlet, folder, filename) values (:tenant, :cloudlet, :folder, '')"
tenant:x:@.tenant
cloudlet:x:@.cloudlet
folder:x:@strings.concat
/*
* Inserting files.
*/
io.file.list-recursively:/
display-hidden:true
for-each:x:-/*
io.file.load.binary:x:@.dp/#
strings.split:x:@.dp/#
.:/
unwrap:x:+
.filename:x:@strings.split/0/-
remove-nodes:x:@strings.split/0/-
strings.join:x:@strings.split/*
.:/
strings.concat
.:/files/
get-value:x:@strings.join
.:/
strings.replace:x:-
.://
.:/
cql.execute:"insert into files (tenant, cloudlet, folder, filename, content) values (:tenant, :cloudlet, :folder, :filename, :content)"
tenant:x:@.tenant
cloudlet:x:@.cloudlet
folder:x:@strings.replace
filename:x:@.filename
content:x:@io.file.load.binary
remove-nodes:x:../**/io.folder.list-recursively/*
remove-nodes:x:../**/io.file.list-recursively/*
Internals
This project is created to be a multi-tenant solution, implying multiple users, and/or cloudlets, can use the same physical
database for both files, log entries, and cache entries. However, this implies you are able to correctly resolve the
"tenant" parts and the "cloudlet" parts for all the above tables. How to achieve this is currently beyond the scope
of this document, but our suggestion is to create some sort of IRootResolver
service implementation that is dynamically
created according to the Host
HTTP header of requests.
Project website
The source code for this repository can be found at github.com/polterguy/magic.data.cql, and you can provide feedback, provide bug reports, etc at the same place.
Quality gates
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CassandraCSharpDriver (>= 3.17.1)
- magic.lambda.caching (>= 14.5.7)
- magic.lambda.logging (>= 14.5.7)
- magic.node.extensions (>= 14.5.7)
- magic.signals (>= 14.5.7)
- Microsoft.Extensions.Configuration (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
14.5.7 | 489 | 12/13/2022 |
14.5.5 | 546 | 12/6/2022 |
14.5.1 | 470 | 11/23/2022 |
14.5.0 | 430 | 11/18/2022 |
14.4.5 | 523 | 10/22/2022 |
14.4.1 | 432 | 10/22/2022 |
14.4.0 | 465 | 10/17/2022 |
14.3.1 | 605 | 9/12/2022 |
14.3.0 | 405 | 9/10/2022 |
14.1.3 | 693 | 8/7/2022 |
14.1.2 | 431 | 8/7/2022 |
14.1.1 | 420 | 8/7/2022 |
14.0.14 | 486 | 7/26/2022 |
14.0.12 | 470 | 7/24/2022 |
14.0.11 | 430 | 7/23/2022 |
14.0.10 | 433 | 7/23/2022 |
14.0.9 | 418 | 7/23/2022 |
14.0.8 | 512 | 7/17/2022 |
14.0.5 | 563 | 7/11/2022 |
14.0.4 | 684 | 7/6/2022 |
14.0.3 | 669 | 7/2/2022 |
14.0.2 | 618 | 7/2/2022 |
14.0.0 | 834 | 6/25/2022 |
13.4.0 | 2,070 | 5/31/2022 |
13.3.4 | 1,421 | 5/9/2022 |
13.3.1 | 692 | 5/1/2022 |
13.3.0 | 658 | 5/1/2022 |
13.2.0 | 1,169 | 4/21/2022 |
13.1.0 | 1,024 | 4/7/2022 |
13.0.0 | 701 | 4/5/2022 |
11.0.5 | 1,403 | 3/2/2022 |
11.0.4 | 730 | 2/22/2022 |
11.0.3 | 728 | 2/9/2022 |
11.0.2 | 747 | 2/6/2022 |
11.0.1 | 745 | 2/5/2022 |
10.0.21 | 748 | 1/28/2022 |
10.0.20 | 720 | 1/27/2022 |
10.0.19 | 715 | 1/23/2022 |