Moving a model class to a database class.

I have an array of objects that represents the model of my application.

It was recommended that rather than use an array of these object to hold my model, that I port my data into an in memory database.
I assume each entry in the array is a row in the database and that each property of the class is represented by a column of the table.

What would you do to the existing class that minimizes the impact of now using a row of an in memory database to hold an instance of the model object?

My first thoughts are:

  1. use a constructor method to insert the new object into the database.
  2. convert each property into a computed property with getters and setters that are ‘database’ aware.

My concerns are about the new column which is the foreign key, i guess that needs to be exposed in the class…

so there is several ways to skin this cat.

ActiveRecord uses a database for the data, and each row in a table is an object. full class based object. methods. properties. events. etc. then when you create a new object, it will create the row in the table. AR can use in memory SQLiteDatabases.

Now I am not saying you need to use AR (I used the hell out of it). But that generally methodology is a good way to do what you are looking at doing,

Good luck…
sb

Thanks Scott. Is AR a design pattern I should follow or is this a toolkit you are recommending I use?

Either. I use the tool all the time. If you choose not to use the tool, use it as a design pattern.

Love it.

ARGen allows you to setup/tweak your database and generate all the classes necessary to use ActiveRecord. There is a freebie mode that allows you to generate two tables at a time. The fully paid version does not have that restriction and also allows you to generate UI to get a jumpstart on your project.

For more information go to http://www.bkeeney.com/allproducts/argen/

Thanks Bob! Very nice work. I had written something like this for a POS systems a long time ago in Z80!
I’m curious about step 1 connecting to a database… I’ve used MySQLWorkbench to define my tables and relationships…
but I don’t have a DB to open.
I have exported the sql create statements from the tool, but again… this isn’t a database file.

I’m not sure I understand. You created a MySQL Database but can’t connect to it from ARGen? ARGen will work with MySQL.

Let me restate. Using MySQLWorkBench I designed my database schema.
I would like to use ARGen to generate my MCV classes, but I need a .db file.
I would like my Xojo app to use an in memory SQLite database.
Am I confused?

Well, somewhere along the way, ARGen will need an actual database with the tables already defined to work. If you plan on using SQLite I suggest using an actual SQLite editor to create what you want. That way ARGen will create the classes for SQLite (not MySQL).

The other reason to use an SQLite tool is that generated SQL will be more SQLite specific. Navicat has a freebie version, I believe. There is also a free SQLiteManager plugin for FireFox that’s pretty handy.

From one BOB to another… Thanks.

ohh bohy… can’t create a db unless its MySQL it seems…
SQLite seems to have tools to create schemas etc but they are not free…

Check out Navicat for SQLite (it has a free, lite, version). Also check out the FireFox plugin called SQLiteManager. A quick Google search showed http://sqlitebrowser.org but I’ve never used it.

There are several SQLite tools that are free. I am sitting in a breakfast meeting or I would post some links. (Don’t have them on the phone)

Go to http://alternative.to (the URL is from memory so it might be off) and you can search for tools by plugging in one tool similar to what you are looking for.

Navigation is a good tool. I used to use the Pro version but feel behind on updates.

Have a good morning!

“SQLiteManager” works with Xojo Encrypted Databases. http://www.sqlabs.com/sqlitemanager.php

SQLiteManager for Firefox does not. Just to clarify. https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/

any tools written in Xojo have that potential. And any tools that use SQLite SEE extension as its encryption methodology.