diff --git a/lbbulk/__init__.py b/lbbulk/__init__.py index dab7f7d..93f7ddb 100644 --- a/lbbulk/__init__.py +++ b/lbbulk/__init__.py @@ -2,10 +2,7 @@ from pyramid.config import Configurator from sqlalchemy import engine_from_config from lbbulk.config.routing import make_routes -from lbbulk.models import ( - DBSession, - Base, - ) +from lbbulk.model import Base, metadata, DBSession def main(global_config, **settings): diff --git a/lbbulk/model/Registro.py b/lbbulk/model/Registro.py new file mode 100644 index 0000000..5297580 --- /dev/null +++ b/lbbulk/model/Registro.py @@ -0,0 +1,27 @@ +from sqlalchemy import Table, Column, Integer, \ + String, join, ForeignKey +from sqlalchemy.orm import column_property +from lbbulk.model import Base, metadata + +# define two Table objects +bulk_sources = Table('lb_bulk_sources', metadata, + Column('id_source', Integer, primary_key=True), + Column('nome_source', String), + ) + +bulk_upload = Table('lb_bulk_upload', metadata, + Column('id_reg', Integer, primary_key=True), + Column('chave_externa', String) + Column('id_source', Integer, ForeignKey('lb_bulk_sources.id_source')), + ) + +# define a join between them. This +# takes place across the bulk_sources.id_source and bulk_upload.id_source +# columns. +registro = join(bulk_sources, bulk_upload) + +# map to it +class Registro(Base): + __table__ = registro + + id_source = column_property(bulk_sources.c.id_source, bulk_upload.c.id_source) \ No newline at end of file diff --git a/lbbulk/model/__init__.py b/lbbulk/model/__init__.py new file mode 100644 index 0000000..49efc4f --- /dev/null +++ b/lbbulk/model/__init__.py @@ -0,0 +1,7 @@ +from sqlalchemy import MetaData +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import scoped_session, sessionmaker + +metadata = MetaData() +Base = declarative_base() +DBSession = scoped_session(sessionmaker()) \ No newline at end of file diff --git a/lbbulk/models/Registro.py b/lbbulk/models/Registro.py deleted file mode 100644 index 62a3969..0000000 --- a/lbbulk/models/Registro.py +++ /dev/null @@ -1,32 +0,0 @@ -from sqlalchemy import Table, Column, Integer, \ - String, MetaData, join, ForeignKey -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import column_property - -metadata = MetaData() - -# define two Table objects -bulk_sources = Table('lb_bulk_sources', metadata, - Column('id_source', Integer, primary_key=True), - Column('nome_source', String), - ) - -bulk_upload = Table('lb_bulk_upload', metadata, - Column('id_reg', Integer, primary_key=True), - Column('chave_externa', String) - Column('id_source', Integer, ForeignKey('lb_bulk_sources.id_source')), - ) - -# define a join between them. This -# takes place across the user.id and address.user_id -# columns. -user_address_join = join(user_table, address_table) - -Base = declarative_base() - -# map to it -class AddressUser(Base): - __table__ = user_address_join - - id = column_property(user_table.c.id, address_table.c.user_id) - address_id = address_table.c.id \ No newline at end of file diff --git a/lbbulk/models/__init__.py b/lbbulk/models/__init__.py deleted file mode 100644 index 5bb534f..0000000 --- a/lbbulk/models/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# package diff --git a/lbbulk/views.py b/lbbulk/views.py index a14ca39..a093812 100644 --- a/lbbulk/views.py +++ b/lbbulk/views.py @@ -1,8 +1,6 @@ from pyramid.response import Response from pyramid.view import view_config -from sqlalchemy.exc import DBAPIError - @view_config(route_name='home', renderer='templates/mytemplate.pt') def my_view(request): -- libgit2 0.21.2