Giter Club home page Giter Club logo

litedb's Introduction

LiteDB - A .NET NoSQL Document Store in a single data file

Join the chat at https://gitter.im/mbdavid/LiteDB Build status Build Status

First v5-alpha version was released

LiteDB is a small, fast and lightweight NoSQL embedded database.

  • Serverless NoSQL Document Store
  • Simple API, similar to MongoDB
  • 100% C# code for .NET 4.5 / NETStandard 2.0 in a single DLL (less than 300kb)
  • Thread-safe
  • ACID with full transaction support
  • Data recovery after write failure (WAL log file)
  • Datafile encryption using DES (AES) cryptography
  • Map your POCO classes to BsonDocument using attributes or fluent mapper API
  • Store files and stream data (like GridFS in MongoDB)
  • Single data file storage (like SQLite)
  • Index document fields for fast search (up to 32 indexes per collection)
  • LINQ support for queries
  • SQL-Like commands to access/transform data
  • LiteDB Studio - Nice UI for data access
  • Pretty fast - compare results with SQLite here
  • Open source and free for everyone - including commercial use
  • Install from NuGet: Install-Package LiteDB

New v5

Take a look at the all new version v5 here

LiteDB Studio

Try online

Try LiteDB Web Shell. For security reasons, in the online version not all commands are available. Try the offline version for full feature tests.

Documentation

Visit the Wiki for full documentation. For simplified chinese version, check here.

Download

Download the source code or binary only in LiteDB Releases

How to use LiteDB

A quick example for storing and searching documents:

// Create your POCO class
public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
    public string[] Phones { get; set; }
    public bool IsActive { get; set; }
}

// Open database (or create if doesn't exist)
using(var db = new LiteDatabase(@"MyData.db"))
{
    // Get customer collection
    var col = db.GetCollection<Customer>("customers");

    // Create your new customer instance
    var customer = new Customer
    { 
        Name = "John Doe", 
        Phones = new string[] { "8000-0000", "9000-0000" }, 
        Age = 39,
        IsActive = true
    };

    // Create unique index in Name field
    col.EnsureIndex(x => x.Name, true);

    // Insert new customer document (Id will be auto-incremented)
    col.Insert(customer);

    // Update a document inside a collection
    customer.Name = "Joana Doe";

    col.Update(customer);

    // Use LINQ to query documents (with no index)
    var results = col.Find(x => x.Age > 20);
}

Using fluent mapper and cross document reference for more complex data models

// DbRef to cross references
public class Order
{
    public ObjectId Id { get; set; }
    public DateTime OrderDate { get; set; }
    public Address ShippingAddress { get; set; }
    public Customer Customer { get; set; }
    public List<Product> Products { get; set; }
}        

// Re-use mapper from global instance
var mapper = BsonMapper.Global;

// "Products" and "Customer" are from other collections (not embedded document)
mapper.Entity<Order>()
    .DbRef(x => x.Customer, "customers")   // 1 to 1/0 reference
    .DbRef(x => x.Products, "products")    // 1 to Many reference
    .Field(x => x.ShippingAddress, "addr"); // Embedded sub document
            
using(var db = new LiteDatabase("MyOrderDatafile.db"))
{
    var orders = db.GetCollection<Order>("orders");
        
    // When query Order, includes references
    var query = orders
        .Include(x => x.Customer)
        .Include(x => x.Products) // 1 to many reference
        .Find(x => x.OrderDate <= DateTime.Now);

    // Each instance of Order will load Customer/Products references
    foreach(var order in query)
    {
        var name = order.Customer.Name;
        ...
    }
}

Where to use?

  • Desktop/local small applications
  • Application file format
  • Small web applications
  • One database per account/user data store
  • Few concurrent write operations

Plugins

Changelog

Change details for each release are documented in the release notes.

License

MIT

Copyright (c) 2019 - Maurício David


LiteDB v5

After more than a year of hard working, v5 is comming!

What's new in v5?

  • New Storage Engine

    • New WAL (Write-Ahead Logging) for fast durability
    • Database lock per collection
    • MultiVersion Concurrency Control (Snapshots & Checkpoint)
    • Multi concurrent Stream readers - Single async writer
    • No lock for reader
    • Up to 32 indexes per collection
    • Atomic multi-document transactions
    • PageSize: 8KB
  • New BsonExpression

    • New super-fast tokenizer parser
    • Clean syntax with optional use of $
    • Input/Output parameter support: @name
    • Simplified document notation { _id, name, year }
    • Support partial BSON document: read/deserialize only used data in query
    • New Map function $.Items => UPPER(@.Name)
  • System Collections

    • Support query over internal collection
    • $transactions, $database, $dump
  • New QueryBuilder

    • Fluent API for write queries
    • Simple syntax using BsonExpressions
    • Support OrderBy/GroupBy expressions
    • Query optimization with Explain Plan
    • Aggregate functions
    • LINQ to BsonExpression query support - easy to use (and similar to EF)
  • New SQL-Like syntax

    • Simple SQL syntax for any command
    • Syntax near to SQL ANSI
    • Support INSERT/UPDATE/DELETE/...
    • MapReduce using GroupBy/Having
  • New Native UI - LiteDB.Studio

    • WinForms app to manipulate the database
    • Based on SQL commands
    • Show results in grid or as text
    • Multi tabs, multi threads, multi transactions

What was dropped?

  • Single process only - optimized for multi thread (open file as exclusive mode)
  • Dropped .NET 3.5/4.0 - works only in .NET 4.5+ and .NETStandard 2.0
  • Shell commands (use SQL commands)

.. but still...

  • Embedded support
  • Single database file
  • Single DLL, no dependencies and 100% C#
  • 100% free open source

Roadmap: The first beta version will be released in Aug/2019

litedb's People

Contributors

mbdavid avatar jensschadron avatar falahati avatar negue avatar mkosieradzki avatar szurgot avatar nerai avatar skysper avatar franzalex avatar lbnascimento avatar izackp avatar blowin avatar tetious avatar sergey-oleynik avatar schulz3000 avatar michal-novak-pos-digital avatar olehfb avatar jlvidal avatar eqqon avatar mstum avatar apkd avatar xied75 avatar michaelstum avatar rdstevens avatar trueromanus avatar ronnieoverby avatar tbroadley avatar thomaslevesque avatar wgross avatar zaid-ajaj avatar

Watchers

James Cloos 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.