Hi there, I have a quick question.
I'm trying out the new v5-aplha version. From what I understand this should support a new SQL-like query syntax? But the documentation it still a bit scarce about this.
Is it possible to use a SQL-like query from code? For exmaple, something like:
using (var db = new LiteDatabase("test.db"))
{
var result = db.Query("SELECT $ FROM Books WHERE Title = 'Acme'");
}
Thanks in advance.
Hi @chinookproject,
I'm glad to inform you that you were really close to it.
The code you need to is something like this (which gives you a list of BsonDocuments).
using (var db = new LiteDatabase(new MemoryStream()))
{
using (var bsonReader = db.Execute("SELECT $ FROM Books WHERE Title = 'Acme'"))
{
var output = new List<BsonValue>();
while (bsonReader.Read())
{
output.Add(bsonReader.Current);
}
return output;
}
}
Please note though that you will still need to do the conversion from BsonDocuments to actual class objects yourself (unless there's some way I don't know about yet).
I think this answers your question so I'm going to close the issue. If it hasn't, feel free to re-open the issue and tell what's still missing. (Please also note that v5 is still in the beta stage and documentation isn't finished yet) 馃檪
Most helpful comment
Hi @chinookproject,
I'm glad to inform you that you were really close to it.
The code you need to is something like this (which gives you a list of BsonDocuments).
Please note though that you will still need to do the conversion from BsonDocuments to actual class objects yourself (unless there's some way I don't know about yet).
I think this answers your question so I'm going to close the issue. If it hasn't, feel free to re-open the issue and tell what's still missing. (Please also note that v5 is still in the beta stage and documentation isn't finished yet) 馃檪