Обсуждение: CRUD plpgsql generator

Поиск
Список
Период
Сортировка

CRUD plpgsql generator

От
Wim Bertels
Дата:
Hallo,

does anyone have know of a free CRUD generator
for generating plpgsql functions for doing CRUD operations on all the
tables of a database or schema or just one table or..

cf

http://postgresql.1045698.n5.nabble.com/CRUD-functions-similar-to-SQL-stored-procedurs-for-postgresql-tables-td3372030.html
http://myleshenderson.com/index.php/2007/11/16/postgresql-insert-function-generator

mvg,
Wim


Re: CRUD plpgsql generator

От
Merlin Moncure
Дата:
On Wed, Jun 22, 2011 at 5:40 AM, Wim Bertels <wim.bertels@khleuven.be> wrote:
> Hallo,
>
> does anyone have know of a free CRUD generator
> for generating plpgsql functions for doing CRUD operations on all the
> tables of a database or schema or just one table or..
>
> cf
>
http://postgresql.1045698.n5.nabble.com/CRUD-functions-similar-to-SQL-stored-procedurs-for-postgresql-tables-td3372030.html
> http://myleshenderson.com/index.php/2007/11/16/postgresql-insert-function-generator

It wouldn't be that difficult to make one IMO, but are you sure you
really want to do this? ISTM it's a bit of an anti-pattern.  If I had
to do it, I would make a plpgsql function which would generate the
functions by querying information_schema and generating create
function statements via 'execute'.

merlin

Re: CRUD plpgsql generator

От
Rob Sargent
Дата:

On 06/22/2011 08:02 AM, Merlin Moncure wrote:
> On Wed, Jun 22, 2011 at 5:40 AM, Wim Bertels <wim.bertels@khleuven.be> wrote:
>> Hallo,
>>
>> does anyone have know of a free CRUD generator
>> for generating plpgsql functions for doing CRUD operations on all the
>> tables of a database or schema or just one table or..
>>
>> cf
>>
http://postgresql.1045698.n5.nabble.com/CRUD-functions-similar-to-SQL-stored-procedurs-for-postgresql-tables-td3372030.html
>> http://myleshenderson.com/index.php/2007/11/16/postgresql-insert-function-generator
>
> It wouldn't be that difficult to make one IMO, but are you sure you
> really want to do this? ISTM it's a bit of an anti-pattern.  If I had
> to do it, I would make a plpgsql function which would generate the
> functions by querying information_schema and generating create
> function statements via 'execute'.
>
> merlin
>
Or a cheasy script to parse the ddl files and generate the functions?

Re: CRUD plpgsql generator

От
Merlin Moncure
Дата:
On Wed, Jun 22, 2011 at 9:59 AM, Rob Sargent <robjsargent@gmail.com> wrote:
> On 06/22/2011 08:02 AM, Merlin Moncure wrote:
>> On Wed, Jun 22, 2011 at 5:40 AM, Wim Bertels <wim.bertels@khleuven.be> wrote:
>>> Hallo,
>>>
>>> does anyone have know of a free CRUD generator
>>> for generating plpgsql functions for doing CRUD operations on all the
>>> tables of a database or schema or just one table or..
>>>
>>> cf
>>>
http://postgresql.1045698.n5.nabble.com/CRUD-functions-similar-to-SQL-stored-procedurs-for-postgresql-tables-td3372030.html
>>> http://myleshenderson.com/index.php/2007/11/16/postgresql-insert-function-generator
>>
>> It wouldn't be that difficult to make one IMO, but are you sure you
>> really want to do this? ISTM it's a bit of an anti-pattern.  If I had
>> to do it, I would make a plpgsql function which would generate the
>> functions by querying information_schema and generating create
>> function statements via 'execute'.
>>
>> merlin
>>
> Or a cheasy script to parse the ddl files and generate the functions?

I greatly prefer the information schema route, because parsing out the
necessary bits robustly is more work than it appears on the surface --
you'd want to be able to handle all manner of primary keys for
example.  IOW, even if you really wanted the function creation script
to be in say, perl, I'd still source the data from a query unless
there was no other route.

merlin

Re: CRUD plpgsql generator

От
Rob Sargent
Дата:

On 06/22/2011 09:10 AM, Merlin Moncure wrote:
> On Wed, Jun 22, 2011 at 9:59 AM, Rob Sargent <robjsargent@gmail.com> wrote:
>> On 06/22/2011 08:02 AM, Merlin Moncure wrote:
>>> On Wed, Jun 22, 2011 at 5:40 AM, Wim Bertels <wim.bertels@khleuven.be> wrote:
>>>> Hallo,
>>>>
>>>> does anyone have know of a free CRUD generator
>>>> for generating plpgsql functions for doing CRUD operations on all the
>>>> tables of a database or schema or just one table or..
>>>>
>>>> cf
>>>>
http://postgresql.1045698.n5.nabble.com/CRUD-functions-similar-to-SQL-stored-procedurs-for-postgresql-tables-td3372030.html
>>>> http://myleshenderson.com/index.php/2007/11/16/postgresql-insert-function-generator
>>>
>>> It wouldn't be that difficult to make one IMO, but are you sure you
>>> really want to do this? ISTM it's a bit of an anti-pattern.  If I had
>>> to do it, I would make a plpgsql function which would generate the
>>> functions by querying information_schema and generating create
>>> function statements via 'execute'.
>>>
>>> merlin
>>>
>> Or a cheasy script to parse the ddl files and generate the functions?
>
> I greatly prefer the information schema route, because parsing out the
> necessary bits robustly is more work than it appears on the surface --
> you'd want to be able to handle all manner of primary keys for
> example.  IOW, even if you really wanted the function creation script
> to be in say, perl, I'd still source the data from a query unless
> there was no other route.
>
> merlin

Undoubtedly you're on the better track.  I equate CRUD with simplistic
and that I'm sure will continue to get me into trouble. So what is a
CRUD generic read function: "select * from table where any field matches
given value"? :)  Or does one punt and just do findByPrimaryKey?



Re: CRUD plpgsql generator

От
Wim Bertels
Дата:
On Wed, 2011-06-22 at 09:02 -0500, Merlin Moncure wrote:
> On Wed, Jun 22, 2011 at 5:40 AM, Wim Bertels <wim.bertels@khleuven.be> wrote:
> > Hallo,
> >
> > does anyone have know of a free CRUD generator
> > for generating plpgsql functions for doing CRUD operations on all the
> > tables of a database or schema or just one table or..
> >
> > cf
> >
http://postgresql.1045698.n5.nabble.com/CRUD-functions-similar-to-SQL-stored-procedurs-for-postgresql-tables-td3372030.html
> > http://myleshenderson.com/index.php/2007/11/16/postgresql-insert-function-generator
>
> It wouldn't be that difficult to make one IMO, but are you sure you
> really want to do this? ISTM it's a bit of an anti-pattern.  If I had

that's another question/debate

cf
http://pyrseas.wordpress.com/2011/06/13/to-mvc-or-not-to-mvc/
and many more

there are so many ways to achieve the same goal:
- it is not only the model,
but certainly the way u use it that is important
- every aproach has it pros/cons
- eg a layered approach can be handy (cf other paradigm where this works
very nice and clear: OSI (networking))
- is the question of what is fashionable (cf scala being the new python,
where most of the devs are well skilled as i isnt mainstream yet)

> to do it, I would make a plpgsql function which would generate the
> functions by querying information_schema and generating create
> function statements via 'execute'.

tnx,
i will

mvg,
Wim

>
> merlin