csStorage 0.1.4

dotnet add package csStorage --version 0.1.4
                    
NuGet\Install-Package csStorage -Version 0.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="csStorage" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="csStorage" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="csStorage" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add csStorage --version 0.1.4
                    
#r "nuget: csStorage, 0.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package csStorage@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=csStorage&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=csStorage&version=0.1.4
                    
Install as a Cake Tool

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.

  • csKey is an attribute that can be used with any type of property, and the selected property must exist when creating the record.
  • csAutoKey is 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

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.4 304 5/17/2023
0.1.3 273 5/5/2023

- added async methods
- added auto generated csKey
- added ability to set storage path