Glorp + Postgres array type

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

Glorp + Postgres array type

xx397
Hi, does anyone know if Glorp supports the array type in Postgres? I did
a basicExecuteSQLString: and it came back with '{1,2,3}' so as if it
might not be too complicated to make work for my scenario at least. I
really want to do a toManyMapping using these integers in the array as a
join to another table and have it resolve their objects, but wouldn't
know where to start!

Thanks
Chris

Reply | Threaded
Open this post in threaded view
|

Re: Glorp + Postgres array type

Guillermo Polito
Hi Chris, I'm not really sure Glorp supports that... but at least I can try to give a look at how the driver responds to it, so:

- Which driver are you using? OpenDBX or the native postgres one? 
- can you provide me some script to setup the problem? I'm not really an expert on postgresql specifics :)

On Sun, Mar 17, 2013 at 11:46 AM, Chris <[hidden email]> wrote:
Hi, does anyone know if Glorp supports the array type in Postgres? I did a basicExecuteSQLString: and it came back with '{1,2,3}' so as if it might not be too complicated to make work for my scenario at least. I really want to do a toManyMapping using these integers in the array as a join to another table and have it resolve their objects, but wouldn't know where to start!


I'll forward this question to the glorp and DBXtalk lists also, probably someone else has more idea.
 
Thanks
Chris

Tx,
Guille
Reply | Threaded
Open this post in threaded view
|

Re: Glorp + Postgres array type

xx397
Hi Guillermo, thanks for that. I'm using DBX for legacy reasons but there's no reason why it couldn't use native.

I managed to get it working by looking at how some other DatabaseTypes worked but am not sure whether I'm doing it completely right. It won't perform a full toManyMapping so I'm just making do with directly mapping the id's and then doing another read in the post fetch to get at the joined objects.

On a similar note, I noticed that Glorp isn't retrieving two objects with a composite SQL statement when you specify a one to one mapping in the descriptor. It is fetching the first and then leaving a Proxy in the second; which will only go to the database with a separate query when you actually ask for it. I have a few cases where having the objects fully resolved at startup might be better than doing each one on demand. Is there any better way to do this than a loop in the post fetch? It also caused me a little confusion because as soon as you do something such as put them into a Set, the = matching of a real Object against a new Proxy that comes along won't work unless you've explicity defined equality (Proxy = Object does in fact work because it does a getValue first) I was trusting Glorp to only allow one instance of a particular object and therefore expecting identity equality to be sufficient

!PostgreSQLPlatform methodsFor: '*glorp-extensions' stamp: 'user 3/19/2013 05:13'!
arrayConverter
    ^DelegatingDatabaseConverter
        named: #array
        hostedBy: self
        fromStToDb: #toArray:for:
        fromDbToSt: #readArray:for:.! !

!PostgreSQLPlatform methodsFor: '*glorp-extensions' stamp: 'user 3/19/2013 05:14'!
arrayOf: elementType
    ^self typeNamed: #arrayOf, elementType asString ifAbsentPut: [GlorpPGArrayType new elementType: elementType ].! !

!PostgreSQLPlatform methodsFor: '*glorp-extensions' stamp: 'user 3/19/2013 05:13'!
readArray: anObject for: aType
    anObject ifNil: [^nil].
    ^((anObject copyFrom: 2 to: anObject size - 1) subStrings: ',') collect: [:each | aType elementType fromString: each]! !

!PostgreSQLPlatform methodsFor: '*glorp-extensions' stamp: 'user 3/19/2013 05:13'!
toArray: anObject for: aType
    anObject ifNil: [^nil].
    ^'{', anObject asCommaString, '}'! !
   
GlorpDatabaseType subclass: #GlorpPGArrayType
    instanceVariableNames: 'elementType'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'Glorp-Extensions'!

!GlorpPGArrayType methodsFor: 'as yet unclassified' stamp: 'user 3/19/2013 05:03'!
converterForStType: aClass
    ^self platform converterNamed: #array.! !


!GlorpPGArrayType methodsFor: 'accessing' stamp: 'user 3/19/2013 05:05'!
elementType
    ^ elementType! !

!GlorpPGArrayType methodsFor: 'accessing' stamp: 'user 3/19/2013 05:05'!
elementType: anObject
    elementType := anObject! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

GlorpPGArrayType class
    instanceVariableNames: ''!

!GlorpPGArrayType class methodsFor: 'as yet unclassified' stamp: 'user 3/19/2013 05:05'!
of: elementType
    ^self new elementType: elementType! !
 

--- On Mon, 18/3/13, Guillermo Polito <[hidden email]> wrote:

From: Guillermo Polito <[hidden email]>
Subject: Re: [Pharo-users] Glorp + Postgres array type
To: "A friendly place where any question about pharo is welcome" <[hidden email]>
Cc: [hidden email], [hidden email]
Date: Monday, 18 March, 2013, 11:41

Hi Chris, I'm not really sure Glorp supports that... but at least I can try to give a look at how the driver responds to it, so:

- Which driver are you using? OpenDBX or the native postgres one? 
- can you provide me some script to setup the problem? I'm not really an expert on postgresql specifics :)

On Sun, Mar 17, 2013 at 11:46 AM, Chris <cpmbailey@...> wrote:
Hi, does anyone know if Glorp supports the array type in Postgres? I did a basicExecuteSQLString: and it came back with '{1,2,3}' so as if it might not be too complicated to make work for my scenario at least. I really want to do a toManyMapping using these integers in the array as a join to another table and have it resolve their objects, but wouldn't know where to start!


I'll forward this question to the glorp and DBXtalk lists also, probably someone else has more idea.
 
Thanks
Chris

Tx,
Guille