ORM for Xojo?

I’ve been away from Xojo for four years, doing C#/Blazor stuff (and others) but the last few evenings have been having a lot of fun (flashbacks!) working on a Mac desktop project with Xojo.

But I’m getting to the point where I need to do database stuff (SQLite) and was wondering if anybody created an ORM such as Dapper or even Entity Framework while I was gone? :slight_smile:

I’ve been programming for 35+ years and my patience for coding housekeeping stuff is pretty much gone, so I’m hoping there’s something out there…?

is DBKit from Geoff Perlman something you can use?

for small data you could serialize your objects to json item and store it.

I didn’t know about DBKit, but at first glance it looks like it could be helpful. Off to browse around it. Thanks!

there is also the argen/activerecord to be considered.

2 Likes

A Google of ‘xojo sqlite orm’ turns up these:

https://github.com/paullefebvre/storm

and

https://github.com/alexvonsiebenthal/BytefactoryORM

The latter is something I have used a lot.

Steve

1 Like

Don’t know what these are. What housekeeping are you referring to?

Those are are known in the C# world, not Xojo stuff.

I just discovered that this solution can suffer from SQL Injection.
An updated version is available here: GitHub - jkleroy/storm: ORM for SQLite and Xojo

5 Likes

We have ORM thing, its not super high on my list though supported (Because of the situation with Xojo Encrypred classes really being open for anyone). It maps SQL queries to entity objects.

Where you can replace Xojo code like this

With this and still maintain speed and get it faster if anything.

Both examples return array of entity class in this case called TestClass.

But it could be any entity obviously, like Address, Employee or whatever the database logically has.

2 Likes

Housekeeping stuff is all code that needs to be in an app in order for it to run, but isn’t specific to that app. Xojo has much less of that than most because it’s not just a programming language, but the thought of writing CRUD code yet freaking again was scraping off the excitement of writing a new app.

Hi @Björn_Eiríksson,

Where would I find this ORM feature? I just looked through your website but couldn’t find any direct mention of it.

Though during my search, I did find your Einhugur SQLite Plugin which I didn’t know you had, so I’m going to check that out.

Thanks.

Thanks – I saw Bytefactory but the fact that it hadn’t been worked on in 10 years had me pass it by. I have enough of my own 10 year old code that no longer works. :wink:

But if you’ve used it, I’ll give it a look (as well as Storm).

You would need to scroll way down…

or use Ctrl-F and use “Einhugur SQL ORM 1.0 for Xojo” as search string.

Most of the non plugin pure Xojo code been in low maintenance mode after it became clear that Encrypted modules dont hold anything, its why it is way at the bottom by now there.

There is always hope they will eventually bring out uhm the compiled reusable Xojo components thing that they been promising.

2 Likes

Found it. I guess I was blind on my first pass through.

Note: I’ve read about the fact that there is a way to decrypt password protect Xojo modules, but I haven’t bothered to figure it out. I’m looking forward to Xojo Libraries as well.

Thank you @Björn_Eiríksson, I’ll have a play with this.

I do recommend ActiveRecord (mentioned above), it was created by database experts – people skilled in building database apps with Xojo. The companion app ARGen will generate the classes and even UI for you, making it easy to get up and running quickly.

I still use both ActiveRecord and ARGen to build apps.

ActiveRecord - the ORM
ARGen - Code, class, and project generator

4 Likes

Humph - maybe my difficulty is knowing what you mean by a “database app”. Among my apps are an email client and an AddressBook app. In teh case of the former I’m making just under 900 calls to ExecuteSQL and SelectSQL - treating databases as handy utility items.

BKeeney Software built many apps that relied on and interacted with databases. As a core part of the toolset, ActiveRecord had to work and it had to work well.

2 Likes

I have made some kind of SQLite wrapper in the past. And I still use it everyday.
It is not public. But I can see if I can bundle something together for you to look at.

It is based on a class that represents the DB.
Other classes can be used as table-records. Where public non-shared properties are the table columns.
The DB-class looks at this record class, to create or modify the DB tables. I did this with Introspection.
This SB-class maps non-DB-compatible field types to something that the DB likes. Like Color, FolderItem, etc, will be mapped to string values. And when populating a record-class, it is transformed back to it original property value.

In the DB class you can define the relationships, where records are deleted, using Triggers.
Other relationship operations include clearing data from certain fields when a related record is deleted.

Below I pasted some code that initializes the DB.

Dim ok As Boolean

'=== CONNECT ===
// This is where the DB is created or connected with
// dmBase is my SQLite DB wrapper
db = new dmBase( dataRoot.Child( appName + ".data" ) )
ok = db.isReady
if not ok then Return false



'=== DEFINE & REGISTER TABLES ===
// This is where tables are created or modified in the DB
Var dUser As New userData(db)
Var dToken As New tokenData(db)
Var dAttempt As New attemptData(db)


'=== DEFINE RELATIONS ===
// In this example, the related records in tokenData and attemptData will be deleted, when a userRecord is deleted.
If ok Then ok = db.addRelationship( dUser, "uuid", dToken, "userID")
If ok Then ok = db.addRelationship( dUser, "uuid", dAttempt, "userID")


'=== HOUSE KEEPING ===
// In my DB I do some user management. Here I remove some "expired" records.
removeExpiredRegistrations
removeExpiredTokens

// In my app I have a "root-user", with a lot of privileges. Here I check if such a user exists, and creates one if there isn't one
checkRootuser


Return ok

This is an example of one of those records. I subclassed it, where it’s super has some saving/deleting/etc logic.
But really, any class will work. Only public non-shared properties are processed in the DB wrapper. This allows for some extra record based logic.