I’ve been using RavenDb for development over the past several years and I’m firmly convinced that there’s a pretty significant productivity advantage to using document databases over relational databases for many systems. For as much as I love many of the concepts and usability of RavenDb, it isn’t running very successfully at work and it’s time to move our applications to something more robust. Fortunately, we’ve been able to dedicate some time toward using Postgresql as a document database. We’ve been able to do this work as a new OSS project called Marten. Our hope with Marten has been to retain the development time benefits of document databases (along with an easy migration path away from RavenDb) with a robust technological foundation — and even I’ll admit that it will occasionally be useful to fall back to using Postgresql as a relational database where that is still advantageous.
I feel like Marten is at a point where it’s usable and what we really need most is some early adopters who will kick the tires on it, give some feedback about how well it works, what’s missing that would make it easier to use, and how it’s performing in their systems. Fortunately, as of today, Marten now has (drum role please):
- An available nuget published to the public Nuget.org feed with very few dependencies (just Npgsql) after I wrestled with ILMerge today (grrr)
- A comprehensive documentation website with a getting started tutorial and plenty of information about what is available and other features that are only planned.
And of course, the Marten Gitter room is always open for business.
An Example Quickstart
To get started with Marten, you need two things:
- A Postgresql database schema (either v9.4 or v9.5)
- The Marten nuget installed into your application
After that, the quickest way to get up and running is shown below with some sample usage:
var store = DocumentStore.For("your connection string");
Now you need a document type that will be persisted by Marten:
public class User { public Guid Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public bool Internal { get; set; } public string UserName { get; set; } }
As long as a type can be serialized and deserialized by the JSON serializer of your choice and has a public field or property called “Id” or “id”, Marten can persist and load it back later.
To persist and load documents, you use the IDocumentSession
interface:
using (var session = store.LightweightSession()) { var user = new User {FirstName = "Han", LastName = "Solo"}; session.Store(user); session.SaveChanges(); }
[new to PostgreSQL]
Are you running PostgreSQL on Windows? Or is a linux box the recommended approach for that part?
Should be good to go with either
I never managed to get ILMerge to work, so I found Cusutra.Fody (https://www.nuget.org/packages/Costura.Fody) that does just the same without the pains of ILMerge.
I’ve written the blog-post about it: http://tech.trailmax.info/2014/01/bundling-all-your-assemblies-into-one-or-alternative-to-ilmerge/