Data Science/3. 데이터 엔지니어링

[n324]ORM(Object Relational Mapping)

착한곰돌e 2021. 7. 20. 09:40

■ Key words

  ㆍORM

  ㆍSQLAlchemy

  ㆍDatabase Engine

 

■ 주요내용

  ㆍObject Relational Mapping : Code와 Database를 연결하여 사용할 때 Database(SQL)의 table을

    code의 class로 작업할 수 있게 mapping하는 것

  ㆍObject Relational Mapper(ORM Library) : layer로 엔진이 나눠있어, 명시만 되어있으면 알아서 돌아감

     - ORM library 중 가장 대표적이고 많이 쓰이는 library가 SQLAlchemy

     - ORM 작동방식 : 

     -Object Relational Impedance Mismatch

  ㆍSQLAlchemy

     - Core : 

     - DBAPI : 

     - ORM

  ㆍ데이터베이스와의 연결

     - 엔진

     - Mapping

     - 테이블 생성

     - 테이블 칼럼

     - 스키마 생성

       · 관계설정 - Foreign Key : 

       · 관계설정 - relationship

       · backref Vs. back_populates

  ㆍSession 생성

  ㆍ데이터베이스 작업

     - Create

     - Delete

  ㆍSession 종료

 

 

■ Session note

  ㆍ

 

■ 주요함수

  ㆍ

 

■ Reference

  ㆍORM : https://gmlwjd9405.github.io/2019/02/01/orm.html

 

[DB] ORM이란 - Heee's Development Blog

Step by step goes a long way.

gmlwjd9405.github.io

  ㆍSQLAlchemy : https://edykim.com/ko/post/getting-started-with-sqlalchemy-part-1/

 

SQLAlchemy 시작하기 – Part 1

edykim.com

  ㆍSQLAlchemy : https://docs.sqlalchemy.org/en/14/orm/basic_relationships.html

 

Basic Relationship Patterns — SQLAlchemy 1.4 Documentation

One To One is essentially a bidirectional relationship with a scalar attribute on both sides. Within the ORM, “one-to-one” is considered as a convention where the ORM expects that only one related row will exist for any parent row. The “one-to-one”

docs.sqlalchemy.org