0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SqlAlchemyテーブル定義を書く時に配列(ARRAY)を格納するカラムがある場合の書き方

Posted at

配列を格納するカラムのテーブル定義を書く方法の例

忘れない様にメモ

「test_tags」のカラムが配列を格納する書き方になっています。

from sqlalchemy import ARRAY, TIMESTAMP, Boolean, Column, Integer, String, text
from sqlalchemy.sql import func
from ..settings.db import Base

class TestTableModel(Base):
    """テスト用テーブルのモデルクラス"""

    __tablename__ = "test_table"

    id = Column(Integer, nullable=False, primary_key=True)
    test_name = Column(String(256), nullable=False)
    test_tags = Column(ARRAY(String(256)), nullable=False)
    test_judge = Column(Boolean, nullable=False)
    delete_flag = Column(
        Boolean,
        nullable=False,
        server_default=text(false),
        index=True,
    )
    create_datetime = Column(
        TIMESTAMP, nullable=False, server_default=func.current_timestamp(), index=True
    )
    update_datetime = Column(
        TIMESTAMP,
        nullable=False,
        server_default=func.current_timestamp(),
        index=True,
    )
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?