Experimenting with Island/DB

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 })) {
            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):

    `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');

The base DB code is in now, I’ll be cleaning up and releasing the sqlite driver later this week.


What is ttpar? Where is it declared?

It was a class ttpar { public int test {get;set;} }

I removed it as an anonymous class works fine too, but forgot to fix the reference. Fixed now.

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:

db.Execute('CREATE TABLE testtable(intfield INTEGER, stringfield INTEGER, PRIMARY KEY(intfield));');

And it will create a table for you.

Thank you. I think this is good enough

Why we need anonymous object? Can’t we just use a plain integer in this case? I am somewhat lost.

@wuping you can have any number of parameters for the query. So you can write it like:

new { par1 = 1, par2 = 15}
new myclass{ par1 = 1, par2 = 15} // now myclass needs to have those properties.

or Oxygene/Swift/Java equivalent.

1 Like

The driver is up at:

the pgsql one too: