SQL

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

SQL

John McKeon
Good day all,
I am looking at the Magritte/Pier "bible" (Reng06a.pdf) Sec 2.3.2 (page 8) Object Relational Mapping. I decided I would take a stab at implementing: "In a very similar way, we are able to automatically create SQL statements to store, load and query objects from a relational database". Any one care to offer hints? I am very much a novice at all these patterns and things, so I am guessing a Visitor pattern of sorts (I HAVE been studying the Gang of Four bible tho ;)....

Here is what I have so far:

MADescription:
 added methods:
>> toSql: anObject    ^self toSql: anObject writer: self sqlWriter.
>>sqlWriter   ^self propertyAt: #sqlWriter ifAbsent: self class defaultSqlWriter.
class>>defaultSqlWriter  ^SQLWriter

And I have created  MAWriter subclass SQLWriter with one instance variable 'sql'
SQLWriter>>defaultWriteStream
    ^((sql isNil ifTrue: [ sql := String new]) writeStream).
SQLWriter>>write: anObject description: aDescription to: aStream
    anObject isNil ifTrue: [ ^ aDescription undefined ].
    ^ super write: anObject description: aDescription to: aStream  which, looking at it now, I really shouldn't need to override

Then there are the visiting method which are going to be the reall tricky part.
SQLWriter>>visitContainer: aDescription
    aDescription memento model isNil  "we have a NEW model object so INSERT"   will this work????? heh
        ifTrue: [ stream nextPutAll: 'INSERT INTO '; nextPutAll: aDescription table; nextPutAll: ' VALUES ('; cr ]  where does the table method come in? hmmm
        ifFalse: [ stream nextPutAll: 'UPDATE '; nextPutAll aDescription table; cr; nextPutAll: 'SET ' ].

And then I will need to add something like:
     aDescription do: [ :desc | self write: something description: desc stream: stream ]     What something goes here I am still scratching my head about...

Any help/suggetions with this last part would be greatly appreciated.

Also, I have started to get used to looking at the unit tests to figure out what things are supposed to do, then I noticed that there are NO tests for MAVisitor and subclasses. Why is that? (Or am I missing something?)

Thanks in advance for any advice
John McKeon





_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: SQL

keith1y
Have you looked a Magritte-RDB package in magritteaddons repository?

Keith

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: SQL

John McKeon
No - are you accusing me of cheating? lol
I will have a look. Thanks Keith

On Sat, Feb 21, 2009 at 6:26 PM, Keith Hodges <[hidden email]> wrote:
Have you looked a Magritte-RDB package in magritteaddons repository?

Keith

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: SQL

Lukas Renggli
In reply to this post by John McKeon
> Also, I have started to get used to looking at the unit tests to figure out
> what things are supposed to do, then I noticed that there are NO tests for
> MAVisitor and subclasses. Why is that? (Or am I missing something?)

There are tests, but the tests do not directly work with the visitors
but indirectly through the descriptions. For example the tests
MAElementDescriptionTest>>#testToString... and #testFromString... test
MAStringReader and MAStringWriter.

I cannot comment on your approach, because I don't exactly know what
you want to do.

Additionally to what Keith pointed out, there is the package
Magritte-Roe in <http://source.lukas-renggli.ch/magritteaddons>. It
depends on ROE and the PostgreSQL drivers (both from SqueakSource) and
provides a simple object mapping mechanism that I used in a few
commercial projects. Usually I prefer to directly persist objects
(instead of relations) though.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: SQL

Damien Cassou-3
In reply to this post by John McKeon
Hi John,

On Sat, Feb 21, 2009 at 11:29 PM, John M <[hidden email]> wrote:
> I am looking at the Magritte/Pier "bible" (Reng06a.pdf) Sec 2.3.2 (page 8)
> Object Relational Mapping. I decided I would take a stab at implementing:
> "In a very similar way, we are able to automatically create SQL statements
> to store, load and query objects from a relational database". Any one care
> to offer hints?

long time ago I had to do a student project and I hacked a link
between Magritte and MySQL: http://www.squeaksource.com/GestionImmo/.

--
Damien Cassou
http://damiencassou.seasidehosting.st

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: SQL

keith1y

> long time ago I had to do a student project and I hacked a link
> between Magritte and MySQL: http://www.squeaksource.com/GestionImmo/.
>  
Magritte-RDB is a contiuation of the ideas in GestionImmo

Keith

p.s. Roe is something I never understood

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: SQL

Lukas Renggli
> p.s. Roe is something I never understood

If you know the Smalltalk Collection hierarchy you know ROE.

ROE provides an interface to be able to filter, collect and iterate
over relational tables exactly the same way as Smalltalk collections.
Magritte-ROE mixes this excellent query interface with basic
meta-described object-relational mapping.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: SQL

John McKeon
I thank you all for your comments.

My original intent was to create _simple_ insert, update and select statements from model descriptions. Skipping relation and reference descriptions, no complex joins etc.

The frameworks suggested are quite robust, and complex, which, being at quite an early stage of learning just about everything (Smalltalk, Seaside, Magritteetc), I am trying to avoid - the complexity that is. It has been a good exercise in delving into the mechanics of Magritte though, so I continue to learn.

GREAT code btw, just a lot to grok.

Also, it would appear that Magritte-ROE requires that Postgresql be _running_ when the package is installed as it failed when trying to connect up a Socket to port 5432.

Thanks again
Warm regards
John

On Sun, Feb 22, 2009 at 1:13 PM, Lukas Renggli <[hidden email]> wrote:
> p.s. Roe is something I never understood

If you know the Smalltalk Collection hierarchy you know ROE.

ROE provides an interface to be able to filter, collect and iterate
over relational tables exactly the same way as Smalltalk collections.
Magritte-ROE mixes this excellent query interface with basic
meta-described object-relational mapping.

Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki