Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/naasking/higherlogics.google.datastore
POCO auto mapper for Google Datastore
https://github.com/naasking/higherlogics.google.datastore
dotnet dotnet-core google-cloud google-datastore-entities mapper poco-auto-mapper
Last synced: 9 days ago
JSON representation
POCO auto mapper for Google Datastore
- Host: GitHub
- URL: https://github.com/naasking/higherlogics.google.datastore
- Owner: naasking
- Created: 2018-03-09T14:36:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T17:33:54.000Z (about 2 years ago)
- Last Synced: 2023-02-28T10:32:09.985Z (almost 2 years ago)
- Topics: dotnet, dotnet-core, google-cloud, google-datastore-entities, mapper, poco-auto-mapper
- Language: C#
- Homepage:
- Size: 104 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HigherLogics.Google.Datastore
A convention-based Google Datastore entities to POCO auto mapper suitable
for small to medium sized projects:using HigherLogics.Google.Datastore;
public class Foo
{
[Key]
public long Baz { get; set; }
public string Bar { get; set; }
}
...
var db = new Google.Cloud.Datastore.V1.DatastoreDb("MyProject");
var fooId = db.Insert(new Foo { Bar = "Hello World!" });
var foo = db.Lookup(fooId, new Foo());
// returns: { Baz : , Bar : "hello world!" }It uses the standard attributes in the `System.ComponentModel.DataAnnotations`
namespace to designate the entity keys.# Custom Value Conversions
Mapping should work for most built in CLR types, including all primitive
types, arrays, dates and nested entities. You can specify any missing
value conversions as follows:Mapper.Convert(from: (Value v) => ...create T,
to: (T obj) => ...create Value);# Integration with Existing Data
By default the full type name is used as the entity kind. To support
integration with existing data sets, you can specify the kind to use
for a given type:Mapper.Kind("Books");
# Query Extensions
You can create a query using one of the following methods:
var query = new Query(Mapper.Kind())
Or:
var db = new Google.Cloud.Datastore.V1.DatastoreDb("MyProject");
...
var query = db.CreateQuery();Result sets from datastore return a sequence of untyped entities which
you can easily convert to a typed sequence as follows:var results = db.RunQuery(query)
.Entities();# Performance Optimizations
By default this library calls Activator.CreateInstance() to construct all
entity types but this is known to be very inefficient. For maximum
performance, I recommend that you override the default constructor for all
of your entity types:Mapper.Constructor(() => new Foo());
This is because I wanted to support environments that don't permit code
generation, and code generation is the only automatic way to efficiently
invoke constructors.However, the IEntityMapper interface can support an implementation that uses
System.Reflection.Emit or LINQ expressions, so you can replace the default
mapping backend as follows:public class YourCustomMapper : IEntityMapper { ... }
Mapper.Default = new YourCustomMapper();
I will probably add a LINQ expression tree mapper at some point in a separate
assembly.# Limitations
* associations to foreign entities must be designated by a property of type
Key as with the usual Datastore API, or the special FK wrapper this library
provides, and they must be manually loaded, inserted, etc. Any nested
reference or value types will be saved as embedded entities. Supporting
proper FK relations starts needing ORM-like features, requiring session-level map
of keys to/from entities, transparent loading of associations and
collections, and other features that can drastically impact performance
* only tuples and value tuples up to 4 arguments are supported out of the box,
as any more than that and you should create a class or struct# Future Work
* LINQ query interface
* add something like [EntityField(string name)] to permit customizing the
entity field names, which will make it easier to integrate with existing
data