def get_file_table(__base__, __metadata__): """ @param base: The base name. @param metadata: A container object from sqlalchemy that keeps together many different features of a database (or multiple databases) being described. @return: Table object. Create a dynamic file Table object to be mapped with LBFile. """ table = Table( #'lb_file_%s' %(__base__), __metadata__, 'lb_file_%s' %(__base__), MetaData(), # @column id_file: The primary key for this table and uniquely identify # each file in the table. Column('id_file', GUID, primary_key=True), # @column id_doc: The primary key for document's table. Each file # belongs to a document. Column('id_doc', Integer), # @column name: Name used to identify a computer file stored in a file # system. Different file systems impose different restrictions on # filename lengths and the allowed characters within filenames. Column('filename', String, nullable=False), # @column file: Sequence of bytes, which means the binary digits (bits) # are grouped in eights. Bytes that are intended to be interpreted as # something other than text characters. Column('file', Binary, nullable=False), # @column mimetype: Internet media type. Standard identifier used on the # Internet to indicate the type of data that a file contains. A media # type is composed of a type, a subtype, and zero or more optional # parameters. Column('mimetype', String, nullable=False), # @column size: Measures the size of @column file in bytes. Column('filesize', Integer, nullable=False), # @column text: Plain text (eletronix text) extracted from @ column # file. Column('filetext', String), # @column dt_ext_text: Date (date and time) of text extraction by # asynchronous text extractor. Column('dt_ext_text', DateTime), # Indicates that this Table is already present in the given MetaData. extend_existing=True, ) # Table factory are the default columns used when query object by API. table.__factory__ = [table.c.id_file, table.c.id_doc, table.c.filename, table.c.mimetype, table.c.filesize, table.c.filetext, table.c.dt_ext_text ] return table
def get_doc_table(__base__, __metadata__, **rel_fields): """ @param base: The base name. @param metadata: A container object from sqlalchemy that keeps together many different features of a database (or multiple databases) being described. @param rel_fields: Dictionary at the format {field_name: field_obj} used to create adicional columns on the table. @return :Table object. Create a dynamic document Table object to be mapped with LBDocument. """ COLUMNS = ( #'lb_doc_%s' %(__base__), __metadata__, 'lb_doc_%s' %(__base__), MetaData(), # @column id_doc: The primary key for this table and uniquely identify # each document in the table. Column('id_doc', Integer, Sequence('lb_doc_%s_id_doc_seq' %(__base__)), primary_key=True), # @column document: JSON encoded data wich represent a base record or # registry. All insertions on this columns must obey the base structure. #Column('document', DocumentJSON, nullable=False), Column('document', JSON, nullable=False), # @column dt_doc: The document's creation date (date and time). Column('dt_doc', DateTime, nullable=False), # @column dt_last_up: The document's last updating date (date and time). Column('dt_last_up', DateTime, nullable=False), # @column dt_del: The document's date (date and time) of deletion. This # date is filled when he normal deletion process failed when deleting # the document index. When it happens, the document is cleared up, # leaving only it's metadata. Column('dt_del', DateTime), # @column dt_idx: The document's date (date and time) if indexing. All # routines that index the document must fill this field. Column('dt_idx', DateTime) ) for rel_field in rel_fields: # Get liblightbase.lbbase.fields object. field = rel_fields[rel_field] custom_col = get_custom_column(field) COLUMNS += (custom_col,) # Create the Table object. extend_existing Indicates that this Table is # already present in the given MetaData. table = Table(*COLUMNS, extend_existing=True) # Table factory are the default columns used when query object by API. table.__factory__ = [ table.c.id_doc, table.c.document, table.c.dt_doc, table.c.dt_del] return table