mitama.db package

Submodules

mitama.db.model module

ベースモデル

  • アプリサイドから触るときに継承させるベースクラス

  • Djangoのdjango.db.modelsみたいなイメージ

  • データベースはユーザー管理をしているものとは別にしたいので、そのつもりで

  • UserとGroupみたいなカスタム型を使えるようになってると良い

  • Flaskのsqlalchemy拡張が参考に成る

class mitama.db.model.Model

ベースクラス: object

create()
delete()
classmethod list(cond=None)
classmethod retrieve(id=None)
type

Model.type.<locals>.Type のエイリアス

update()

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 TypeEngine object, and from there to the DBAPI execute() 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 Dialect in 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 TypeEngine object, originally from the DBAPI cursor method fetchone() 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 Dialect in 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 TypeEngine object, and from there to the DBAPI execute() 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 Dialect in 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 TypeEngine object, originally from the DBAPI cursor method fetchone() 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 Dialect in 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 TypeEngine object, and from there to the DBAPI execute() 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 Dialect in 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 TypeEngine object, originally from the DBAPI cursor method fetchone() 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 Dialect in use.

This operation should be designed to be reversible by the "process_bind_param" method of this class.

Module contents

データベース

データベースの接続とか抽象化の処理を書きます Databaseはシングルトンの接続のインスタンスを生成するクラスです 各アプリにはDatabaseを継承したクラスを定義してもらい、そいつのModelプロパティのベースクラスからモデルを作ってもらいます。

class mitama.db.BaseDatabase(*args, **kwargs)

ベースクラス: mitama.db._Database

アプリで利用するデータベースの操作を行うクラス

アプリからデータベースを使うたい場合、このクラスを継承したクラスをアプリ内に定義します。