ORM module for bah.database

BlitzMax Modules Forums/Brucey's Modules/ORM module for bah.database

Little update, I'm almost off to bed now :-).

I started a TQueryBuilder type which will allow for the easy query building. I'm planning on adding INSERT, SELECT, UPDATE and DELETE support first. Joining might come later on, as well as grouping and all that kind of stuff.

I'm a little worried though about supporting the multiple databases. When INSERTing with MySQL you don't have to specify an auto_increment primary key. But with SQLite it seems I have to. So I need to ponder about how to get that done :-).

So far, a little example:

Local query1:TQueryBuilder = New TQueryBuilder
Local query2:TQueryBuilder = New TQueryBuilder
Local query3:TQueryBuilder = New TQueryBuilder

query1.From("objects").Where("level_id = ?", TDBInt.Set(1)).OrWhere("pos_x > ?", TDBInt.Set(0)).Order("creation_time DESC").Limit(0, 10)
query2.SetType(TQueryBuilder.TYPE_UPDATE).From("objects").Set("pos_x", TDBInt.Set(200)).Where("level_id = ?", TDBInt.Set(1)).Limit(0, 1)
query3.SetType(TQueryBuilder.TYPE_INSERT).From("objects").Set("pos_x", TDBInt.Set(300)).Set("pos_y", TDBInt.Set(400))

Print query1.ToString()
Print query2.ToString()
Print query3.ToString()


Which generates these queries:

SELECT * FROM objects WHERE level_id = ? OR pos_x > ? ORDER BY creation_time DESC LIMIT 0

UPDATE objects SET pos_x = ? WHERE level_id = ? LIMIT 0

INSERT INTO objects (pos_x,pos_y)VALUES(?,?)


Generating the query and binding the values to the query is done with a special method:

query3.bindValues(sth:TDatabaseQuery)


So you just pass a TDatabaseQuery to it.

And now I really need to get some sleep :-)