Experimenting with the new Island DB layer, which lets you write code like:
class tt {
public string stringfield{get;set;}
public Integer intfield{get;set;}
}
static class Program
{
public static Int32 Main(string[] args)
{
var db= new RemObjects.Elements.SqLite.SqliteDbConnection(ConnectionString = "c:\\projects\\test.sqlite2.db");
foreach (var x in db.Query<tt>("select * from testtable where intfield > @test", new { test = 4 })) {
writeLn(x.stringfield);
writeLn(x.intfield);
}
Console.WriteLine("The magic happens here.");
return 0;
}
}
}
Where it fills an Island class based on an sqlite query (a bit like Dapper does on .NET)
(sqlite db used):
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS `testtable` (
`intfield` INTEGER NOT NULL,
`stringfield` INTEGER NOT NULL,
PRIMARY KEY(`intfield`)
);
INSERT INTO `testtable` (intfield,stringfield) VALUES (1,'test55');
INSERT INTO `testtable` (intfield,stringfield) VALUES (2,'test2');
INSERT INTO `testtable` (intfield,stringfield) VALUES (3,'test3');
INSERT INTO `testtable` (intfield,stringfield) VALUES (4,'test1');
INSERT INTO `testtable` (intfield,stringfield) VALUES (5,'test2');
INSERT INTO `testtable` (intfield,stringfield) VALUES (6,'test3');
COMMIT;
The base DB code is in now, I’ll be cleaning up and releasing the sqlite driver later this week.
This is great feature as a light-weight ORM. In addition to querying an existing table, can we use this layer to create new table based on a class definition?
No; I purposefully kept the base classes simple and database independent. But something like this could easily be built on top of this.
(The sql syntax for every different kind of database is quite different, and get even trickier when things like joins are needed). This just takes sql and parameters and executes a command or reader. Note that you CAN do something like: