Menu
Introduction
Getting Started
ID Card
Update Biota Database
Release notes
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
0
Share

PathwayCompound

Model class

:property id: The id of the model (in database) :type id: int :property id: The unique resource identifier of the model :type id: str :property type: The type of the python Object (the full class name) :type type: str :property created_at: The creation datetime of the model :type created_at: datetime :property save_datetime: The last save datetime in database :type last_modified_at: datetime

Attributes
created_at: TypedDateTimeUTCdata: dictid: TypedCharFieldlast_modified_at: TypedDateTimeUTC
Functions
__init__

Initialize self. See help(type(self)) for accurate signature.

clone
coerce
_coerce : bool - True
delete_instance
recursive : bool - False
delete_nullable : bool - False
dependencies
search_nullable : bool - True
exclude_null_children : bool - False
get_id
get_name

Get the name. Alias of :meth:get_title

Return type : str
is_alias
is_dirty
is_saved

Returns True if the model is saved in db, False otherwise

Return type : bool
refresh
Return type : ModelType
save

Sets the data set force_insert to True to force creation of the object set skip_hook to True to skip the before insert or update hook

Return type : Self
set_name

Set the name.

name : str
to_dto
Return type : BaseModelDTO
unwrap
add_index @classmethod
fields : Any
after_all_tables_init @classmethod

Method call after all the table are inited

Useful when use DeferredForeignKey to create the foreign key manually latter

after_table_creation @classmethod

Method call after the table is created

Usefull to create the full text indexes

alias @classmethod
alias : Any
bind @classmethod
database : Any
bind_refs : bool - True
bind_backrefs : bool - True
_exclude : Any
bind_ctx @classmethod
database : Any
bind_refs : bool - True
bind_backrefs : bool - True
bulk_create @classmethod
model_list : Any
batch_size : Any
bulk_update @classmethod
model_list : Any
fields : Any
batch_size : Any
classname @classmethod

Returns the name of the class

slugify : bool - False
True to slugify the class name if True
snakefy : bool - False
True to snakefy the class name if True
replace_uppercase : bool - False
Replace upper cases by "-" if True
Return type : str
column_exists @classmethod

Returns True if the column exists in the table

column_name : str
The column name
Return type : bool
create @classmethod
query : Any
create_all @classmethod

Automically and safely save a list of models in the database. If an error occurs during the operation, the whole transactions is rolled back (if use_transaction=True).

model_list : list
List of models
batch_size : int - 10000
Size of each batch for bulk creation
use_transaction : bool - True
If True, wraps all batches in a single transaction. If False, each batch creates its own transaction (for MariaDB timeout issues)
Return type : list
create_foreign_key_if_not_exist @classmethod

Create a foreign key for a Foreign key field only if the foreign key does not exists

field : Any
[description]
create_full_text_index @classmethod

Method to create a full text index

columns : list
[description]
index_name : str
create_table @classmethod

Create model table

delete @classmethod
delete_by_id @classmethod
pk : Any
drop_table @classmethod

Drop model table

execute_sql @classmethod

Execute a raw SQL query. Can use the [TABLE_NAME] to replace by the table name

query : str
The query to execute
filter @classmethod
dq_nodes : Any
filters : Any
foreign_key_exists @classmethod
column_name : str
Return type : bool
full_classname @classmethod

Returns the full name of the class

slugify : bool - False
Slugify the returned class name if True
snakefy : bool - False
Snakefy the returned class name if True
Return type : str
get @classmethod
query : Any
filters : Any
get_by_id @classmethod
id : str
Return type : Optional
get_by_id_and_check @classmethod

Get by ID and throw 404 error if object not found

id : str
The ID of the model
Return type : ModelType
get_by_ids @classmethod
ids : list
Return type : list
get_db @classmethod
Return type : DatabaseProxy
get_db_manager @classmethod

Returns the (current) DbManager of this model

Return type : AbstractDbManager
get_metadata @classmethod
Return type : ModelMetadata
get_or_create @classmethod
get_or_none @classmethod
arg : Any
get_table_name @classmethod

Returns the table name of this class

Return type : str | None
index @classmethod
fields : Any
index_exists @classmethod

Returns True if the index exists in the table

index_name : str
The index name
Return type : bool
inheritors @classmethod

Get all the classes that inherit this class

insert @classmethod
_Model__data : Any
insert : Any
insert_all @classmethod

Insert multiple items with detailed logging

data : list
List of dictionaries to insert
batch_size : int - 10000
Number of items per batch
use_transaction : bool - True
If True, wraps all batches in a single transaction. If False, each batch uses its own transaction (for MariaDB timeout issues)
insert_from @classmethod
query : Any
fields : Any
insert_many @classmethod
rows : Any
fields : Any
is_mysql_engine @classmethod
is_table @classmethod

Returns True if the class has a table name defined

Return type : bool
noop @classmethod
raw @classmethod
sql : Any
params : Any
replace @classmethod
_Model__data : Any
insert : Any
replace_many @classmethod
rows : Any
fields : Any
save_all @classmethod
search_by_name @classmethod
name : Any
page : int - 1
number_of_items_per_page : int - 50
select @classmethod
fields : Any
set_by_id @classmethod
key : Any
value : Any
table_exists @classmethod
truncate_table @classmethod
options : Any
update @classmethod
_Model__data : Any
update : Any
update_all @classmethod

Automically and safely save a list of models in the database. If an error occurs during the operation, the whole transactions is rolled back (if use_transaction=True).

model_list : list
List of models
fields : list
batch_size : int - 10000
use_transaction : bool - True
If True, wraps bulk_update in a transaction. If False, bulk_update handles its own transactions (for MariaDB timeout issues)
Return type : list
validate_model @classmethod
copy @staticmethod
method : Any
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.