You could put all of your table definitions in one or more functions that 
take a DAL object as an argument:

def standard_tables(db):
    db.define_table('table1', ...)
    db.define_table('table2', ...)
    ...

def api_tables(db):
    db.define_table('table3', ...)
    db.define_table('table4', ...)
    ...

standard_tables(db)
api_tables(db)
api_tables(db_api)

That approach gets trickier if the order of table definitions matters 
(i.e., you need to define some API tables after some standard tables but 
before others).

Another option is to make some table definitions conditional based on the 
request (using the conditional models functionality, or via simple "if" 
statements). That approach will actually be more efficient, as when an API 
request comes in, you won't bother defining all the tables that can't be 
accessed. 

Anthony

On Thursday, December 3, 2015 at 5:24:07 PM UTC-5, Piotr Róż wrote:
>
> Hello everyone,
>
> I'm developing an application where I need to separate rest api functions 
> from other standard www application functions on database permissions 
> level. This means that I want to create:
> - normal database user for standard cases - http requests - first (main) 
> DAL object (db);
> - special database user with limited permissions to read only few tables - 
> api requests - second DAL object (db_api).
>
>  I don't want to create special app for only api code. 
>
> How can I do this without duplicate define_table code for this few tables? 
> Is it possible to do this in one application?
>
> Thanks guys
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to