John Milmine
unread,Feb 16, 2011, 11:13:19 PM2/16/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to SilverStripe Core Development
Attended the meetup last night, thanks all.
Just some thoughts I'd had around database and ORM.
1) Query cache vs Object cache.
Currently SS uses a Query cache which is useful for multiple queries
doing the same query however not so much if you grab 10 objects and
then do a get_by_id. The object is already loaded, but since the
object dsoes't know it, it has to go back to the database to re-
receive the data.
One of the ideas, in a framework I've worked on was an ObjectMap which
is essentially a singleton, with a array of all objects loaded from
the database, keyed by id. This way if an object is already loaded you
don't have to access the database again.
The framework also stored IDs of objects which refer to it as a
foreign key. That way if someone did $car->wheels() the object could
check if all the ids it knew about were already loaded in the
ObjectMap and not touch the db. This however does have performance
issues, and requires parent objects to ALWAYS know about child objects
ids. So can be a bit tricky to implement.
2) Connection Pool
I mentioned this last night. On the same framework, objects statically
knew which database they were associated with. There was also a global
pool on connections strings for each database, that way an object
could connect to the database it was in.
3) After a first attempt of database intregration which worked OK We
re-thought how we would like to write the query and decided that
rather than SQL directly in code, we opted for chain-able queries
(similar to jQuery). We tried to limit the amount of strings and opted
for Objects and statics as much as possible. It also abstracts the
queries enough to remove database specific syntax. We then used a
series of adapters to turn the objects from expressions objects into
expressions the database type would understand.
$prototypeMember = new Member(null, true);
$query->select('ID')->select($prototypeMember, '*')->where('Phone',
Querty::EQUALS, 'asd')->orderby($prototypeMember, 'Firstname');
OR:
$query->select(
$prototypeMember, '*'
)->when(
new WhenExpression('Number', Querty::GT, 6),
new ThenExpression('Order', 2),
new ElseExpression('Order', 1)
)->join(
$prototypeMember,
new Role(null, true),
new Expression('ID', Querty::EQUALS, 'MemberID')
)->groupBy($prototypeMember, 'ID'
)->groupBy($prototypeMember, 'FirstName');
$results = $query->getObjects();
Modelling the way SQL is constructed into objects is difficult,
however we did have over 40 units test working which enabled us to
model queries independent of database type. This experiment was never
finished, although our first attempt allowed us to query MySQL and
MSSQL via PDO with transation support with no change in API. However
the first attempt had a custom query api for those queries that were
too hard to model. The second attempt was to try remove that need.
That however may be a un-realistic goal.
Our over-riding vision was trying to make an API that would adapt a
non-object based database into an Object base query structure.
If you would like to look at the objects created to model sql,
@spronkey will be making them available within the next 7 days. It may
or may not help, and at the very least may just be another way to look
at it and give you some ideas.
4) I mentioned removing MySQL from core in the meeting. Sam mentioned
you want out of the box functionality. I don't see this as a problem,
just because it's not in core, doesn't mean it's not part of the
download package?
Thoughts all?