SQLAlchemyナレッジ
server_default設けれるんやー。これ他のginとかでもできんかな?できそー。
良いね。これ楽。便利。
created_at = Column(TIMESTAMP, server_default=current_timestamp())
updated_at = Column(TIMESTAMP, server_default=current_timestamp())
なるほど。ほなexecute 使わんかったら基本的にSQL injection対策はせんでええねんな。ナイスー
If you have any "special" characters (such as semicolons or apostrophes) in your data, they will be automatically quoted for you by the SQLEngine object, so you don't have to worry about quoting. This also means that unless you deliberately bypass SQLAlchemy's quoting mechanisms, SQL-injection attacks are basically impossible.
ORM
.filter と .filter_by の違い
.filter_by は model名を記述せんでいいから、短く記述できる。
.filter_byだけ使っとけば良さそう。今んとこ.filterを使う利点はなし。
.label でカラム名(key名)を変えれる
DB側で数字から始まるキー名などを使用してる時に、pythonでは数字から始まる変数を使用できないため、.labelを用いてpythonで扱える変数名にlabel付けする必要がある。
0per --> .label('zero_per')
なるほど。<class 'sqlalchemy.engine.row.Row'>
はPythonのtuble/tuplesのsubclassやからimmutable(変更不可)やと。
tupleを変えたいなら、元のtupleから新しい自分が欲しいtupleを作成する必要があると。
Row is a subclass of tuple and tuples in Python are immutable hence don't support item assignment. If you want to replace an item stored in a tuple you have rebuild it from scratch: