Code Monkey home page Code Monkey logo

mdbx.net's Introduction

mdbx.NET

.NET bindings(.NET Standard 2.0) of libmdbx, succeeder of LMDB(Lightning Memory-Mapped Database).

Build status NuGet version

License

This project is licensed under the Apache License, Version 2.0.

The libmdbx library is not shipped with this assembly. And the assembly will load libmdbx from the location below according to your platform and OS.

/mdbx.NET.dll
/native
  ├──/windows
  │   ├──/x86/mdbx.dll
  │   ├──/x64/mdbx.dll
  │   ├──/arm/mdbx.dll
  │   └──/arm64/mdbx.dll
  ├──/linux
  │   ├──/x86/libmdbx.so
  │   ├──/x64/libmdbx.so
  │   ├──/arm/libmdbx.so
  │   └──/arm64/libmdbx.so
  └──/osx
      ├──/x86/libmdbx.so
      ├──/x64/libmdbx.so
      ├──/arm/libmdbx.so
      └──/arm64/libmdbx.so

How to Use

NuGet package is available, first install.

Install-Package mdbx.NET

Here is an example of basic operations.

using MDBX;

using (MdbxEnvironment env = new MdbxEnvironment())
{
    env.SetMaxDatabases(10) /* allow us to use a different db for testing */
        .Open(path, EnvironmentFlag.NoTLS/* flags */, Convert.ToInt32("666", 8)/* permission */ );

    DatabaseOption option = DatabaseOption.Create /* needed to create a new db if not exists */
        | DatabaseOption.IntegerKey/* opitimized for fixed-size int/long key */;

    // mdbx_put
    using (MdbxTransaction tran = env.BeginTransaction())
    {
        MdbxDatabase db = tran.OpenDatabase("basic_op_test", option);
        db.Put(10L, "ten");
        db.Put(1000L, "thousand");
        db.Put(1000000000L, "billion");
        db.Put(1000000L, "million");
        db.Put(100L, "hundred");
        db.Put(1L, "one");
        tran.Commit();
    }


    // mdbx_get
    using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly))
    {
        MdbxDatabase db = tran.OpenDatabase("basic_op_test", option);

        string text = db.Get<long, string>(1000000L);
        Assert.NotNull(text);
        Assert.Equal("million", text);
    }

    // mdbx_del
    using (MdbxTransaction tran = env.BeginTransaction())
    {
        MdbxDatabase db = tran.OpenDatabase("basic_op_test", option);
        bool deleted = db.Del(100L);
        Assert.True(deleted);
        deleted = db.Del(100L);
        Assert.False(deleted);
        tran.Commit();
    }


    // mdbx_get
    using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly))
    {
        MdbxDatabase db = tran.OpenDatabase("basic_op_test", option);

        string text = db.Get<long, string>(100L);
        Assert.Null(text);
    }
}

Here is an example of using cursor

using (MdbxTransaction tran = env.BeginTransaction(TransactionOption.ReadOnly))
{
    MdbxDatabase db = tran.OpenDatabase("cursor_test1");
    using (MdbxCursor cursor = db.OpenCursor())
    {
        string key = null, value = null;
        cursor.Get(ref key, ref value, CursorOp.First);
        // ...
        
        while(cursor.Get(ref key, ref value, CursorOp.Next))
        {
            // ...
        }
    }
}

Please check unit test for more examples

mdbx.net's People

Contributors

wangjia184 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mdbx.net's Issues

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.