How can I assemble SQL with object-oriented Perl? -


I am currently in charge of a process that is very intimate with the database. The goal of my program / script / framework is to create uniformity from uneven data sources Using a form of dependency injection, my process works very well at very high levels. The implementation of each data source type is hidden from the business level of the highest level of what is happening. great. I have two questions

1) I have a long paragraph (and this is the length that is bothering me) that collects the SQL statement in PearlSpace to translate these different data sources into a consistent end. Does the format Therefore, the SQL string always depends on the type of data I am working on. The WHERE section depends, the FROM segment depends, the INSERT volume depends, it all depends on the high level of dependency that is confusing me, how can I model this process in an object-oriented manner? MagicObject-> buildSQL? It is essentially now with me, but it seems that all the parts of the code are very much known, so its length.

2) If I have a function that creates SQL (?), Then I have completed the merchandise and can then prepare them in the last minute? Or do I prepare them sooner and only handle my actions according to the needs of the objects?

Edit : Although I do not doubt the importance of ORM, I do not believe that we are still in ORM space. Imagine baseball data for American, National and Fantasy leagues, wildly stored in different formats with different levels of normalized level. It is my process to read the sources of these data and keep them in an integrated, normalized pool. I think that the IRM space acting on these objects happens after my procedure. I am a type of data visitor, if you will.

Edit ^ 2 : It has been brought to my attention that perhaps I have not described the problem place in the adequate detail. Here's an example.

Imagine that you had to make master database of all criminals in the United States. Your company's service is selling a product that offers this data in a clear, unified format by sitting on top.

This data is publicly provided by 50 states, but wildly in different formats. There is a file of some data, not normalized. There are other generalized tables in the CSV format. Some Excel documents are some TSVs Some records are also provided that are not complete without manual interference (other, manually created data sources) .

The purpose of my project is to make a "driver" for each of the 50 states and ensure that the end product of the process is a prime database of criminals in a model, relationship model. Everything right, schema in the right size, etc.

You . I started using it a few months ago at work, and whenever there are some rough parts of the implementation due to the youth, the idea behind it is solid. Take a lightly optimized query from F.X, manual:

  My $ user = $ schema-> Table ('user'); My $ q = Fey :: SQL - & gt; New_style - & gt; Select ($ user- & gt; column ('user_id', 'username')) - & gt; From ($ user);  

You can now type a function like this:

  sub restricted_v_ group {my ($ q, $ table, @group_id) = @_; My $ group = $ schema- & gt; Table ('group') - & gt; Alias; $ Q - & gt; From ($ table, $ group) - & gt; Where ($ group- & gt; column ('group_id'), 'IN', @group_id); }  

This will add an inner insert from user to group and WHERE condition. And voice, you can write the following in the main program:

  restrict_with_group ($ q, $ user, qw (1 2 3)); << Code>  

But this restrict_with_group function will work for any query in which it has the group Table! To use it, you want to pass the query that you want to restrict and the table to which you want to apply the restriction, as well as the group ID that you want to restrict it to.

In the end you can $ q-> SQL ($ dbh) is called and you get back a string of SQL that you have $ q objects

So basically you have the old capabilities that the original SQL is missing. You can remove reusable aspects from your questions and package them as a separate function.


Comments