question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[PROPOSE] LiteDB in WebHost + Observables

See original GitHub issue

Hi guys, this is a propose to new lib that will works with LiteDB - support for host LiteDB over websockets.

WebSockets

The main idea is host database as a server database but inside in your own web application. API should be like this:

// define entrypoint for LiteDB web hosting
app.UseLiteDB("/litedb", c =>
{
    // host web admin UI to manage your databases
    c.UseWebAdmin(); // na versão free pode ser algo bem simples
    
    // use custom authentication (see below)
    c.UseAuthorization<IAuthorization>();
    
    // register many databases as you want
    c.Register("mydb", new EngineSettings { Filename = "c:/data/mydb.db" });
    c.Register("mydb2", new EngineSettings { Filename = "c:/data/mydb2.db" });
    
    // or create a function to register/create
    c.Register(name => new EngineSettings { Filename = $"c:/data/{name}.db" });
});

This will server LiteDB over HTTP and WebSocket API. Will be possible to connect via normal client:

// connect to you database via web-sockets
var db = new LiteDatabase("ws://localhost:8008/litedb/mydb", "admin", "pwd123");

This websocket remote access will open possibility for another non-.NET languages to connect on LiteDB database, like node or even javascript browser;

// open database as remove address
var db = new LiteDatabase("ws://localhost:8008/litedb/mydb", "admin", "pwd123");

// get collections
var customers = db.getCollection("customers");

// run commands like insert, update, delete or query
customer.insert({ _id: 1, name: 'John' });

Run your database direct from browser javascript will be awesome!

About authentication, you will set lower level what user can to. IAutentication interface will contains:

interface IAutentication
{
    IUser Login(string username, string password)
}

interface IUser
{
    string Username { get; set; } 
    bool HasPermission (DbCommandEnum command,  string collection)
    void OnInsert(BsonDocument document);
    void OnUpdate(BsonDocument document);
    void OnDelete(BsonDocument document);
    void OnQuery(string collection, Query query);
}

With this interface, users will have a fine access to what documents and commands will be executed by this user. Will be possible check insert/update/delete data structure (use JSON.NET Schema validator) or add more required filters in queries (avoid a client read data from another client).

Observables

To offer a better user experence, will be nice if LiteDB reacts from database changes, even in remote envirments. So, the ideia is support observables to run in .NET (or any other language, like javascript).

var db = new Database("ws://localhost:8000/litedb/mydb", "user", "pwd");

var col = db.getCollection("customers");

var s = col.subscribe("CustomerId == 15", function(entity) {
    // detect any change in CustomerId == 15
});

// to unsubscribe
s.close();

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:19 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
FuturistiCodercommented, Mar 3, 2020

@mbdavid check my repos: LiteDB.Realtime I implemented Observables

2reactions
FuturistiCodercommented, Mar 5, 2020

@mbdavid from my code

        public bool Commit()
        {
            var success = _engine.Commit();
            if (success)
            {
                NotificationService.Notify();
            }

            return success;
        }

it will notify only after the commit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - LiteDB :: A .NET embedded NoSQL ...
Getting Started. LiteDB is a simple, fast and lightweight embedded .NET document database. LiteDB was inspired by the MongoDB database and its API...
Read more >
LiteDB :: A .NET embedded NoSQL database
LiteDB is a serverless database delivered in a single small DLL (< 450kb) fully written in .NET C# managed code (compatible with .NET...
Read more >
Search Results - CVE
The mission of the CVE® Program is to identify, define, and catalog publicly disclosed cybersecurity vulnerabilities.
Read more >
2m-subdomains.txt
... subdomains UltimateAndroidGradle API Presentation lua hbase-server groups ... laravel-lte corpus-oa-pmr-v01 LiteDB backstage2 aws-java-sdk-cloudwatch ...
Read more >
Bookmarks
StateMachine // This module implements a lightweight Http server using HttpListener. /// The purpose of the server is to enable inter-process communication
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found