You might try something like this in your module:
dummy_db = DAL('sqlite:memory', do_connect=False, migrate_enabled=False)
def define_tables(db):
db.define_table('mytable', Field('field1'), Field('field2'))
define_tables(dummy_db)
query1 = dummy_db.mytable.field1 == 'some value'
query2 = dummy_db.mytable.field2 == 'other value'
By setting do_connect=False, no connection will be made to the database. Note, the URI used for the dummy database does not have to be the same as the real database, but it should refer to the same type of DBMS (mainly to ensure the the proper SQL dialect is used to generate the SQL).
Then in your model and/or controller code:
from mymodule import define_tables, query1, query2
db = DAL(...)
define_tables(db)
rows = db(query1 & query2).select()
Note, with the above approach, the dummy DAL object defined in the module is not the same DAL object defined in the model/controller code where the query is executed. However, in order to generate queries in the module, we still need to define the tables on the dummy DAL object. So, the above example puts the table definition code in a function, which can be called within the module as well as the model/controller code in order to define the same tables on the real DAL object as well as the dummy object.
Finally, you should consider whether there is really much benefit to defining the queries in a module in this way.
Anthony