Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pblachut committed Apr 6, 2017
1 parent 20f0f86 commit 9d54601
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

Document databases became popular in last years. They have a lot of places where they are suitable to use. RavenDb and many others are doing very well on production sites. This time I`ll tell something about Marten which has feature of document database and event store. The new thing is that Marten works on the top of Postgres database.

## What is it Marten?
===

I`ve heard the first time about Marten on Slack channel when some person shared the link to [this post](https://jeremydmiller.com/2016/08/18/moving-from-ravendb-to-marten/). [Jeremy Miller](https://jeremydmiller.com/) shows why his team decided to abandon RavenDb and setup completly new project with utilizing Postgres relational database. Marten just works as an ORM on Postgres and provides functionality of document database and event store. It is great advantage when single relational database can be used in many ways in the project. But as always, if something is for many things then is the best in nothing.
#### What is it Marten?

I`ve heard the first time about Marten on Slack channel when some person shared the link to [this post](https://jeremydmiller.com/2016/08/18/moving-from-ravendb-to-marten/). [Jeremy Miller](https://jeremydmiller.com/) shows why his team decided to abandon RavenDb and setup completly new project with utilizing Postgres relational database. Marten just works similar to ORM on Postgres and provides functionality of document database and event store. It is great advantage when single relational database can be used in many ways in the project. But as always, if something is for many things then is the best in nothing.

Marten uses [JSONB](https://www.postgresql.org/docs/9.4/static/datatype-json.html) Postgres type to store documents as default. It gives huge efficiency profits in comparision to normal JSON format. JSONB supports [GIN](https://www.postgresql.org/docs/9.1/static/textsearch-indexes.html) indexing with the following [operators](https://www.postgresql.org/docs/9.4/static/functions-json.html#FUNCTIONS-JSONB-OP-TABLE). Postgres gives also possibility to use [full-text search](https://blog.lateral.io/2015/05/full-text-search-in-milliseconds-with-postgresql/) within JSON documents.

## Marten as a document database
#### Marten as a document database

Document database API is very similar to RavenDB what creators of the Marten say openly. They have created Marten as a substitution of RavenDB and that is reason of doing that.

Expand Down Expand Up @@ -49,7 +51,7 @@ DocumentStore.For(storeOptions =>

```

### Database session
#### Database session

It is possible to open modification database session in three different types of mode:
- `_documentStore.LightweightSession()`
Expand All @@ -65,7 +67,7 @@ Session with manually document change tracking. It uses IdentityMap by default.

Session with automatically document change tracking. Change in every document loaded to the session would be detected and then `_session.Store(document)` would be invoked automatically. Dirty tracking session is done by comparising JSON documents node by node so enabling it would influence on the performance significantly.

### Session listeners
#### Session listeners

It is possible to add custom session listeners which can intercept specified action during session unit of work. Such listener must implement `IDocumentSessionListener` interface and must be added during `DocumentStore` configuration. `DocumentSessionListenerBase` is a abstract class which can be used to override specified behaviour. It is not need to implement all listener actions.

Expand All @@ -78,21 +80,19 @@ var store = DocumentStore.For(storeOptions =>
});
```

### Transaction isolation level
#### Transaction isolation level

It is possible to determine transaction isolation level in all above session modes. Default level is `ReadCommitted` but it can be set during opening the session e.g. `_store.DirtyTrackedSession(IsolationLevel.Serializable)`.

### Read-only database session
#### Read-only database session

There is also separate session which was designed only to access database in read-only mode. To create it, it is needed to call `_documentStore.QuerySession()`. Regarding document cache it works the same as in `_documentStore.LightweightSession()`.

### Optimistic concurrency
#### Optimistic concurrency

Marten gives possibility to enable optimistic concurrency feature on specified document type. After enabling it, any document change which would tried to persist is checked firstly if any other change has been done since document was loaded into cache. Such change is detected by comparing version number located in metadata. It is also possible to store document with manually specified version. More information about it can be found in [documentation](http://jasperfx.github.io/marten/documentation/documents/advanced/optimistic_concurrency/).
## Querying

### Linq
#### Querying

Marten supports [synchronous](http://jasperfx.github.io/marten/documentation/documents/querying/linq/) and [asynchronous](http://jasperfx.github.io/marten/documentation/documents/querying/async/) linq queries quite well. It includes e.g. searching in child collections, deep queries, distinct, compiled queries, ordering, paging, select many and document value projections. Interesting thing regards paging (using `Take()`, `Skip()`) is that it is possible to get total count of all records in single query using [Stats()](http://jasperfx.github.io/marten/documentation/documents/querying/paging/) extension. I think that this functionality was influenced by RavenDb which has similar [one](https://ravendb.net/docs/article-page/3.5/csharp/client-api/session/querying/how-to-get-query-statistics).
Expand Down Expand Up @@ -208,7 +208,7 @@ where d.mt_doc_type = 'toyota'

```

## Summary
#### Summary

In my personal opinion Marten looks very promising as an alternative to other document databases but cannot be compared directly with them. E.g. RavenDb was created from scratch to build document database when Marten is just a software layer on relational database. Marten gives a foothold for teams which are used to use relational databases. On the other hand, if we would like to see Marten advantages over RavenDb, Marten is fully [ACID](https://en.wikipedia.org/wiki/ACID). RavenDb supports it only in some [queries](https://ayende.com/blog/164066/ravendb-acid-base).
Expand Down
Binary file modified banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9d54601

Please sign in to comment.