mitama.db package¶
Submodules¶
mitama.db.model module¶
ベースモデル
アプリサイドから触るときに継承させるベースクラス
Djangoのdjango.db.modelsみたいなイメージ
データベースはユーザー管理をしているものとは別にしたいので、そのつもりで
UserとGroupみたいなカスタム型を使えるようになってると良い
Flaskのsqlalchemy拡張が参考に成る
mitama.db.types module¶
型定義
ノリで書いたから自分でもよくわからないけど、データベースのカスタム型を定義してみた
イメージとしては、データベースの実体には各モデルのidプロパティが入る
取り出すときは数字からそれに対応するモデルのインスタンスが還ってくる
当然、↓のコードはUser.getなんて関数は用意してないので動かないと思われ
-
class
mitama.db.types.Group(*args, **kwargs)¶ ベースクラス:
sqlalchemy.sql.type_api.TypeDecorator-
impl¶ sqlalchemy.sql.sqltypes.Integerのエイリアス
-
process_bind_param(value, dialect)¶ Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngineobject, and from there to the DBAPIexecute()method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
- パラメータ
value -- Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect -- the
Dialectin use.
-
process_result_value(value, dialect)¶ Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngineobject, originally from the DBAPI cursor methodfetchone()or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
- パラメータ
value -- Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect -- the
Dialectin use.
This operation should be designed to be reversible by the "process_bind_param" method of this class.
-
-
class
mitama.db.types.Node(*args, **kwargs)¶ ベースクラス:
sqlalchemy.sql.type_api.TypeDecorator-
impl¶ sqlalchemy.sql.sqltypes.Integerのエイリアス
-
process_bind_param(value, dialect)¶ Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngineobject, and from there to the DBAPIexecute()method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
- パラメータ
value -- Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect -- the
Dialectin use.
-
process_result_value(value, dialect)¶ Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngineobject, originally from the DBAPI cursor methodfetchone()or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
- パラメータ
value -- Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect -- the
Dialectin use.
This operation should be designed to be reversible by the "process_bind_param" method of this class.
-
-
class
mitama.db.types.User(*args, **kwargs)¶ ベースクラス:
sqlalchemy.sql.type_api.TypeDecorator-
impl¶ sqlalchemy.sql.sqltypes.Integerのエイリアス
-
process_bind_param(value, dialect)¶ Receive a bound parameter value to be converted.
Subclasses override this method to return the value that should be passed along to the underlying
TypeEngineobject, and from there to the DBAPIexecute()method.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
This operation should be designed with the reverse operation in mind, which would be the process_result_value method of this class.
- パラメータ
value -- Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect -- the
Dialectin use.
-
process_result_value(value, dialect)¶ Receive a result-row column value to be converted.
Subclasses should implement this method to operate on data fetched from the database.
Subclasses override this method to return the value that should be passed back to the application, given a value that is already processed by the underlying
TypeEngineobject, originally from the DBAPI cursor methodfetchone()or similar.The operation could be anything desired to perform custom behavior, such as transforming or serializing data. This could also be used as a hook for validating logic.
- パラメータ
value -- Data to operate upon, of any type expected by this method in the subclass. Can be
None.dialect -- the
Dialectin use.
This operation should be designed to be reversible by the "process_bind_param" method of this class.
-