반응형

Schema 생성 방법

 

> go run -mod=mod entgo.io/ent/cmd/ent new Schema

> go generate ./ent
반응형

'framework > entgo' 카테고리의 다른 글

DB Table을 가지고 Schema 자동 생성  (0) 2023.08.30
반응형

DB Table을 가지고 Schema 자동 생성

** 참고하지만 실제 시도는 아래 순서 따라 진행: https://entgo.io/he/blog/2021/10/11/generating-ent-schemas-from-existing-sql-databases/#getting-started**

 

 

실행 순서

  1. ent schema 폴더와 generate.go 파일 생성
    go run -mod=mod entgo.io/ent/cmd/ent new

  2. entimport 설치
    go run -mod=mod ariga.io/entimport/cmd/entimport -h

  3. DB에 따라 다르게 입력
    ** 여기서 만약 table에 primary key가 없으면 에러가 발생하며 schema를 생성해주지 않습니다. primary key를 생성하면 작동합니다. **
    mysql: go run ariga.io/entimport/cmd/entimport -dialect mysql -dsn "root:pass@tcp(localhost:3306)/entimport"
    postgreSQL: go run ariga.io/entimport/cmd/entimport -dsn "postgres://tuba_om_user:Okestro2018\!@10.10.10.135:5432/tuba_om?sslmode=disable" -tables "vt_event, vt_event_rule" -schema-path "./"

  4. table .go 가 schema 폴더 아래 잘 생성이 되었으면 아래 코드를 작동
    go generate ./ent
반응형

'framework > entgo' 카테고리의 다른 글

Schema 생성 방법  (0) 2023.08.30

+ Recent posts