기타

[python] sqlacodegen 데이터 ORM

vhxpffltm 2022. 1. 27. 22:27
반응형

.db 나 .csp 파일의 내용을 파이썬 코드로 가져올 수 있는 모듈이다.

 

https://github.com/agronholm/sqlacodegen

 

GitHub - agronholm/sqlacodegen: Automatic model code generator for SQLAlchemy

Automatic model code generator for SQLAlchemy. Contribute to agronholm/sqlacodegen development by creating an account on GitHub.

github.com

 

데이터 베이스의 내용을 바탕으로 SQLAlchemy 모델 코드를 생성해준다. 

 

SQLAlchemy는 따로 공부해야 할것이고 이를 통해 파이썬으로 DB 데이터들을 활용할 수 있게된다.

 

* 당연히 pip를 통해 패키지를 다운받고 실행하자*

 

sqlacodegen --outfile test.py "sqlite:///[path].db

 

와 같이 실제 서버가 아닌 로컬의 db 파일도 모듈화 할 수 있다.

 

여기서 중요한 점이 하나 있는데 sqlite와 mysql 일때 약간 문제가 있다.

 

Sqlite의 파일을 지정할 경우 “sqlite://“가 아닌 “sqlite:///“ 로 /를 3번 써주셔야 상대경로로 지정 가능하며, “sqlite:////“로 /를 4번 써주셔야 절대경로로 지정이 가능하다.

 

https://stackoverflow.com/questions/28788186/how-to-run-sqlacodegen

 

How to run sqlacodegen?

I'm not understanding why I can't run sqlacodegen. I'm looking to use it for create a SQLAlchemy model from my existing PostgreSQL database. It won't run. When I type sqlacodegen --help for he...

stackoverflow.com

 

 

반응형

'기타' 카테고리의 다른 글

[Vscode] C++ 디버깅 및 단축키  (0) 2022.02.13
[Blockchain] 테스트서버에 코인만들기  (0) 2022.02.03
[Cmake] Cmake 와 Google test  (0) 2022.01.27
[vscode] python format 설정과 launch.json  (0) 2022.01.19
[vscode] python 설정  (0) 2022.01.19