Git Product home page Git Product logo

elephanet's Introduction

Build Status ##Elephanet - A .NET document database built on PostgreSQL.##

###With an api thats easy to use###

A document db api backed by Postgresql.

Heavily influenced by the RavenDb .NET client, this libary provides a simple api to allow easy use of postgres as a document store, taking advantage of Postgresql 9.4 and its new jsonb indexing, allowing for fast querying of native json objects.

###Quick Start

For Windows

  1. Install Postgresql > 9.4 (available at http://www.postgresql.org/download/windows/). When you do so, pay particular attention to your postgres user password (you will need this in the next step)
  2. Clone (or fork) this repository
  3. Alter create_store.sql file and replace "my super secret password" with your own password
  4. Run create_store.bat from within a cmd prompt.

For Ubuntu (and likely other Debian based distros)

  1. Install Postgresql via apt-get. Make sure it is greater than version 9.4
  2. Install Mono (http://www.mono-project.com/docs/getting-started/install/linux/)
  3. Clone (or fork) this repository
  4. Alter create_store.sql file and replace "my super secret password" with your own password
  5. run psql -f create_store.sql -U postgres

###Got Questions?

###Example Code

using System;

public class Car
{
 	public Guid Id {get;set;}
	public string Make {get;set;}
	public string Model {get;set;}
	public string ImageUrl {get;set;}
	public string NumberPlate {get;set;}
}
	//create the datastore
	DocumentStore store = new DocumentStore("Server=127.0.0.1;Port=5432;User Id=store_user;password=my super secret password;database=store;");
	
	
	//create the object
	var myAudi = new Car {
		Id = Guid.NewGuid(),
		Make = "Audi",
		Model = "A8",
		ImageUrl = "http://some_image_url",
		NumberPlate = "ABC029"
	};

	//save the object to the document store
	using (var session = store.OpenSession())
	{
		session.Store<Car>(myAudi);
		session.SaveChanges();
	}

	//get the same car back out of the document store
	using (var session = store.OpenSession())
	{
		var car = session.GetById<Car>(myAudi.Id);
	}


	//create a couple of other cars	
	var myFord = new Car {
		Id = Guid.NewGuid(),
		Make = "Ford",
		Model = "Mustang",
		ImageUrl = "http://some_image_url",
		NumberPlate = "XYZ999"
	};

	var myOldAudi {
		Id = Guid.NewGuid(),
		Make = "Audi",
		Model = "A5",
		ImageUrl = "http://some_image_url",
		NumberPlate = "ABC002"
	};

	//store these other cars
	using (var session = store.OpenSession())
	{
		session.Store<Car>(myOldAudi);
		session.Store<Car>(myFord);
		session.SaveChanges();
	}

	//update existing object
	using (var session = store.OpenSession())
	{
		var audi = session.GetById<Car>(myOldAudi.Id);
		audi.Image_Url = "http://some_new_url";

		session.Store<Car>(audi);
		session.SaveChanges();
	}

	//query by make
	using (var session = store.OpenSession())
	{
		var audis = session.Query<Car>().Where(c => c.Make == "Audi").ToList();
	}

	//delete
	using (var session = store.OpenSession())
	{
		session.Delete<Car>(myOldAudi.Id);
	}

	//delete all of a particular type
	using (var session = store.OpenSession())
	{
		session.DeleteAll<Car>();
	}
	

###Currently implemented###

  • You can session.Store<T>(T entity)
  • You can session.SaveChanges();
  • You can session.GetById<T>(Guid id)
  • You can session.GetByIds<T>(IEnumerable<Guid> ids)
  • You can session.Delete<T>(Guid id)
  • You can session.GetAll<T>();
  • You can session.DeleteAll<T>();
  • You can session.Query<T>(x => x.SomeAttribute == "some value").ToList();
  • You can session.Query<T>(x => x.SomeAttribute == "some value").Take(10).Skip(5);
  • You can session.Query<T>(x => x.SomeAttribute == "some value").OrderBy(c => c.SomeOtherAttibute);
  • You can session.Query<T>(x => x.SomeAttribute == "some value").OrderByDescending(c => c.SomeOtherAttibute);

###Things of note:

  • You can implement your own custom json serialization (Jil is internalised by default)
  • Store() is a unit of work stored in memory. SaveChanges() flushes the in memory values to the database

elephanet's People

Contributors

jmkelly avatar fwise avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

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.