Giter VIP home page Giter VIP logo

halforbit / data-stores Goto Github PK

View Code? Open in Web Editor NEW
14.0 6.0 6.0 644 KB

Data Stores lets you use simple cloud storage to create serverless, distributed, highly available, low-cost databases and caches with sophisticated keying, richly structured values, and compression at-rest. Data Stores integrates with a wide variety of storage providers and formats, all using a single, simple abstraction.

License: MIT License

C# 100.00%
azure azure-storage blob-storage caching compression csv database distributed document-database files

data-stores's Introduction

Halforbit Data Stores

License  Build status  Nuget Package

Data Stores lets you use simple cloud storage to create serverless, distributed, highly available, low-cost databases and caches with sophisticated keying, richly structured values, and compression at-rest.

Data Stores integrates with a wide variety of storage providers and formats, all using a single, simple abstraction.

Features

  • Inexpensive Serverless Databases: Use simple cloud storage to create serverless, distributed, highly available, low-cost databases.

  • Easy Distributed Caches: Create persistent caches to increase performance of backend API controllers, or reduce the number of calls to expensive third-party web APIs.

  • Many Supported Storage Providers: Including Azure Blobs, Azure Tables, Amazon S3, FTP, SFTP, and Local File Storage.

  • Many Supported Formats: Including human-readable structured data like JSON and YAML, efficient structured binary data with Bond or Protobuf, delimited tabular data like CSV and TSV, and binary data such as images and raw text.

  • Optional Compression: Flip a switch and compress data payloads up to 10x with GZip or LZMA, improving response times and reducing storage and bandwidth costs.

  • One Easy Abstraction: Trade in your error prone bare metal integrations and high ceremony repository patterns for a single, elegant IDataStore interface that is uniform across storage platforms and formats.

Getting Started

  1. Install NuGet Packages: Install the NuGet packages for your desired storage providers and formats:

    Install-Package Halforbit.DataStores

    See the NuGet Packages section below for a list of available NuGet packages and what storage providers and formats they support.

  2. Define Your Stores: Use the DataStore type to create ad-hoc stores, or define them as properties on a data context.

  3. Use Your Stores: Persist and retrieve data with your stores, or inspect write times, sizes, metadata and more with the stores' Context property.

There are many options to choose from when creating a store. A store can:

  • be defined as a property of a data context, or created ad-hoc and stored in a local variable.
  • be keyed with simple types like Guid or string, with the properties of a class, record, or struct, or be a keyless singleton storing a single value.
  • store values as simple types like string or byte[], or structured class, record, or struct types serialized as e.g. JSON or TSV.

Example Usage

Let's make a simple ad-hoc store to persist a record value using Azure Blobs, formatted as JSON, and key it with the properties of a record key.

First, we define a type to represent our value:

public record Person(
    string Department,
    Guid PersonId,
    string FirstName,
    string LastName);

Next we define a type to represent our key:

public record PersonKey(
    string Department,
    Guid PersonId);

Next we create a store ad-hoc with a key type of PersonKey, and a value type of Person:

var store = DataStore
    .Describe()
    .BlobStorage()
    .ConnectionString("<connection-string-here>")
    .Container("<container-name-here>")
    .ContentType("application/json")
    .DefaultContentEncoding()
    .JsonSerialization()
    .NoCompression()
    .FileExtension(".json")
    .Map<PersonKey, Person>(k => $"people/{k.Department}/{k.PersonId}")
    .Build();

The Map<,> method lets us define a bi-directional mapping between a PersonKey and a string.

Note that people here is acting similarly to a table or collection name, and the Department property is acting as a kind of partition key.

Now we can put a Person in the store with the Upsert method:

var key = new PersonKey(
    Department: "development",
    PersonId: Guid.NewGuid());

var value = new Person(
    Department: key.Department,
    PersonId: key.PersonId,
    FirstName: "Steve",
    LastName: "Smith");

await store.Upsert(key, value);

We can get a Person by their PersonKey:

var value = await store.Get(key);

We can delete a Person by their PersonKey:

await store.Delete(key);

We can list the PersonKeys in the store, optionally filtered by PersonKey.Department:

var keys = await store.ListKeys(k => k.Department == "development");

We can get all of the Persons in the store, optionally filtered by PersonKey.Department:

var values = await store.ListValues(k => k.Department == "development");

NuGet Packages

The following NuGet packages are provided, parted out by their dependencies. Install the ones that contain the storage providers and formats you wish to use.

Storage Provider or Format NuGet Package
Local File Storage, JSON Serialization, Raw Byte Serialization, GZip Compression Halforbit.DataStores
Azure Blob Storage Halforbit.DataStores.FileStores.BlobStorage
Azure Table Storage Halforbit.DataStores.TableStores.AzureTables
Amazon S3 Storage Halforbit.DataStores.FileStores.AmazonS3
YAML Serialization Halforbit.DataStores.FileStores.Serialization.Yaml
Protobuf Serialization Halforbit.DataStores.FileStores.Serialization.Protobuf
Bond Serialization Halforbit.DataStores.FileStores.Serialization.Bond
LZMA Compression Halforbit.DataStores.FileStores.Compression.Lzma

License

Data Stores is licensed under the MIT License. See the LICENSE file for details.

data-stores's People

Contributors

akrock avatar halforbit avatar jimn-purecars avatar jimnoble avatar ryanoshag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

data-stores's Issues

Autofac dependecy

Hi,
Thanks for the interesting library. However, I was rather disappointed by the fact of how much dependencies are being installed. Could you please consider removing Autofac at least from the target build if you are not using it in the particurlar implementation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.