[PROPOSE] LiteDB in WebHost + Observables
See original GitHub issueHi 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:
- Created 4 years ago
- Reactions:6
- Comments:19 (4 by maintainers)
Top GitHub Comments
@mbdavid check my repos: LiteDB.Realtime I implemented Observables
@mbdavid from my code
it will notify only after the commit.