csStorage 0.1.4
dotnet add package csStorage --version 0.1.4
NuGet\Install-Package csStorage -Version 0.1.4
<PackageReference Include="csStorage" Version="0.1.4" />
<PackageVersion Include="csStorage" Version="0.1.4" />
<PackageReference Include="csStorage" />
paket add csStorage --version 0.1.4
#r "nuget: csStorage, 0.1.4"
#:package csStorage@0.1.4
#addin nuget:?package=csStorage&version=0.1.4
#tool nuget:?package=csStorage&version=0.1.4
csStorage
csStorage is a data storage system that allows the user to easily execute CRUD operations on csv file. The system maps class entieties to csv files using unique key for each record.
Getting started
csStorage is a lightweight package that is ready to use as soon as you add the nuget to your solution.
Entity
The first step in using the package is to create an entity that inherits from csEntityBaseModel<T> and choose which class property is the key that will be used to query data later.
To do this, set the [csKey] or [csAutoKey] attribute to one of the properties.
csKeyis an attribute that can be used with any type of property, and the selected property must exist when creating the record.csAutoKeyis an attribute that can only be used with int or Guid type properties and can be generated automatically when creating a record.
public class Cat : csEntityBaseModel<Cat>
{
[csKey]
public string? Name { get; set; }
public int Age { get; set; }
}
public class Dog : csEntityBaseModel<Dog>
{
[csAutoKey]
public int Id { get; set; }
public string? Name { get; set; }
public int Age { get; set; }
}
Builder
To execute CRUD operations using csStorage You must initialize a new csContextBuilder<T> class instance.
var contextCatBuilder = new csContextBuilder<Cat>();
When You need to change the path of csv file storage You can simply override a SetDirectoryPath() method.
public class CsContextDogBuilder<Dog> : csContextBuilder<Dog>
{
protected override void SetDirectoryPath()
{
var appDomainDir = AppDomain.CurrentDomain.BaseDirectory;
this.DirectoryPath = Path.GetFullPath(Path.Combine(appDomainDir, @"..\..\..\csvFiles\"));
}
}
var contextDogBuilder = new CsContextDogBuilder<Dog>();
Data operations
The package allows You to execute basic operations on data sets.
Create
To create a new record in csv file You just need to create a new instance of entity and use Add() or AddAsync() method.
var catEntity = new Cat {
Name = "Ding",
Age = 5
}
contextCatBuilder.Add(catEntity);
var dogEntity = new Dog {
Name = "Dong",
Age = 7
}
await contextDogBuilder.AddAsync(dogEntity);
var dogEntityId = contextDogBuilder.csKey;
Get
Quering the data can be done using Get() or GetAsync() method.
To query the data you can choose between two overload types:
- the no parameter one - query the whole data collection,
- the key parameter one - query one record using unique key (type of int, string, Guid or DateTime).
var catsOlderThanFour = contextCatBuilder.Get().Where(x => x.Age > 4).ToList();
var myDog = await contextDogBuilder.GetAsync(dogEntityId);
Update
To update record You need to query entity what needs to be updated, modify it, and use method Update() or UpdateAsync() to save changes.
var myDog = await contextDogBuilder.GetAsync(dogEntityId);
myDog.Name = "Dong Dung";
await contextDogBuilder.UpdateAsync(myDog);
Delete
To Delete You only need to call Delete() or DeleteAsync() using csKey as a parameter.
contextCatBuilder.Delete(catEntity.Name);
await contextDogBuilder.DeleteAsync(dogEntityId);
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to create tests for new features or bug fixes.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- CsvHelper (>= 30.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- added async methods
- added auto generated csKey
- added ability to set storage path