{"id":581,"date":"2026-07-20T17:47:13","date_gmt":"2026-07-20T08:47:13","guid":{"rendered":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/581"},"modified":"2026-07-20T17:47:13","modified_gmt":"2026-07-20T08:47:13","slug":"sqlalchemy%e3%81%a8%e3%81%af","status":"publish","type":"post","link":"https:\/\/www.marchboy.xyz\/wordpress\/archives\/581","title":{"rendered":"SQLAlchemy\u3068\u306f"},"content":{"rendered":"<h2>SQLAlchemy\u306e\u6982\u8981<\/h2>\n<p>SQLAlchemy\u306f\u3001Python\u5411\u3051\u306eORM\uff08Object Relational Mapper\uff09\u304a\u3088\u3073SQL\u30c4\u30fc\u30eb\u30ad\u30c3\u30c8\u3067\u3059\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u7684\u306b\u8a18\u8ff0\u3067\u304d\u3001SQL\u6587\u3092\u76f4\u63a5\u66f8\u304f\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h2>\u4e3b\u306a\u7279\u5fb4<\/h2>\n<ul>\n<li><strong>ORM\u3068\u30b3\u30a2\u306e2\u5c64\u69cb\u9020<\/strong>\uff1a\u9ad8\u30ec\u30d9\u30eb\u306eORM\u3068\u4f4e\u30ec\u30d9\u30eb\u306eSQL Expression Language\uff08\u30b3\u30a2\uff09\u3092\u4f75\u7528\u3067\u304d\u308b\u3002<\/li>\n<li><strong>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u62bd\u8c61\u5316<\/strong>\uff1aMySQL\u3001PostgreSQL\u3001SQLite\u3001Oracle \u306a\u3069\u591a\u6570\u306eDB\u3092\u540c\u4e00\u30b3\u30fc\u30c9\u3067\u6271\u3048\u308b\u3002<\/li>\n<li><strong>\u81ea\u52d5\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3068\u306e\u9023\u643a<\/strong>\uff1aAlembic \u306a\u3069\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u30b9\u30ad\u30fc\u30de\u7ba1\u7406\u304c\u3067\u304d\u308b\u3002<\/li>\n<\/ul>\n<h2>\u7c21\u5358\u306a\u4f7f\u7528\u4f8b<\/h2>\n<h3>ORM\u3092\u4f7f\u3063\u305f\u30c6\u30fc\u30d6\u30eb\u5b9a\u7fa9<\/h3>\n<pre><code>from sqlalchemy import Column, Integer, String, create_engine\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy.orm import sessionmaker\n\nBase = declarative_base()\n\nclass User(Base):\n    __tablename__ = 'users'\n    id = Column(Integer, primary_key=True)\n    name = Column(String(50))\n    age = Column(Integer)\n\nengine = create_engine('sqlite:\/\/\/example.db')\nBase.metadata.create_all(engine)\n\nSession = sessionmaker(bind=engine)\nsession = Session()\n\nnew_user = User(name='Alice', age=30)\nsession.add(new_user)\nsession.commit()\n<\/code><\/pre>\n<h3>SQL Expression Language\uff08\u30b3\u30a2\uff09\u3092\u4f7f\u3063\u305f\u30af\u30a8\u30ea<\/h3>\n<pre><code>from sqlalchemy import select, Table, MetaData\n\nmetadata = MetaData()\nusers = Table('users', metadata, autoload_with=engine)\n\nstmt = select([users.c.name, users.c.age]).where(users.c.age > 25)\nfor row in engine.execute(stmt):\n    print(row)\n<\/code><\/pre>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>SQLAlchemy\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089\u5927\u898f\u6a21\u306a\u30a8\u30f3\u30bf\u30fc\u30d7\u30e9\u30a4\u30ba\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u307e\u3067\u5e45\u5e83\u304f\u5bfe\u5fdc\u3067\u304d\u308b\u67d4\u8edf\u306a\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30c4\u30fc\u30eb\u3067\u3059\u3002ORM\u306e\u751f\u7523\u6027\u3068SQL\u30b3\u30a2\u306e\u5236\u5fa1\u6027\u3092\u4e21\u7acb\u3055\u305b\u305f\u3044\u5834\u5408\u306b\u7279\u306b\u6709\u52b9\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQLAlchemy\u306e\u6982\u8981 SQLAlchemy\u306f\u3001Python\u5411\u3051\u306eORM\uff08Object Relational Mapper\uff09\u304a\u3088\u3073SQL\u30c4\u30fc\u30eb\u30ad\u30c3\u30c8\u3067\u3059\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u7684\u306b\u8a18\u8ff0\u3067\u304d\u3001SQL\u6587\u3092\u76f4\u63a5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-web-service"],"_links":{"self":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":0,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marchboy.xyz\/wordpress\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}