So continuing on with the attribute fun today in the Moose-pen I am going to have a look at my 'Element' Database::Accessor class. So far like View there is not much to it only 'alias' and 'name'

Now putting my fore-ward looking Moose glasses you can see that I am going to need some more attributes. Well in SQL this class is being used as a field so I will need at least a 'table name' but then again I do not have a table in Classes so I guess I need a 'View' object now I could do this.





has 'view' => (

is => 'rw',

isa => 'View',

);



and make it a View class but that would be a little overkill. Now I do not want to make it just a string as well I really want to stop silly mistake like “users's” or “single use” or even “$_per_hr” in other words I want some way to clean out most of the nasty annoying characters.

Now I can't program all the possible limitations in here, I know for Oracle it can by anything as long as you warp it in “” and in Mongo I know it can't start with '$' or be empty so maybe I will just leave it as a 'Str' and let whoever is writing the DAD worry about it. So I am going with this





has 'view' => (

is => 'rw',

isa => 'Str',

);





has 'aggregate' => (

is => 'rw',

isa => 'Str',

);



Now another one that would go in here is an aggregate function. Same problem again there are some eight Mongo aggregates and many dozens of SQL depending on which flavour you choose. So I will just leave it as a 'Str' for now as wellNow another field attribute that comes to mind is 'distinct', present in both SQL and Mongo however this is clause modifier in Oracle and a command in Mongo so not really related to an element so that one can be left out.

One I am going to add in is 'is_identity' which is going to get some use in the SQL DAD especially for those DBs that do not use an auto-sequencer. Not sure how much use Mongo will get out of is as no real concept in that db of an identity field constraint so





has 'is_identity' => (

is => 'rw',

isa => 'bool',

);





has 'predicate' => (

is => 'rw',

isa => 'Predicate',

);





--use Moose;

with qw(Database::Accessor::Roles::Alias);

++use Moose;

with qw(Database::Accessor::Roles::Alias Database::Accessor::Types);



Now the final one for today is when a field may be an expression like 'price * qty' in SQL or '{ $multiply: [ 'price', 'qty' ] }' in Mongo. Now in SQL there is also a function like 'substr(contact_detail.value, 1,2 )' or in mongo '{ $substr: [ value, 1,2 ] }}'. Now in my classes I have something very close to this in the Predicate class so maybe I need this.now that leaves me with a little problem I now I have to import my types into the Element class which is as easy asI just add in the Types Role. Now I going to have to spend some time look at this to see if any of this will work out. I guess I knows tomorrows topic.

Anway here is a joke because of today's short post