-
-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adiciona possibilidade de uso com MongoDB #278
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revisei apenas a parte de integração (ou seja, ainda não olhei para a implementação do MongoDB em si, db/mongo.go
e seus testes), mas muito bom! Feliz demais com essa colaboração!
Deixei alguns comentários, tem coisas que ainda não precisamos mudar antes de dar merge, mas tá muito bom!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mais comentários, ainda sem chegar no módulo do MongoDB, ainda focando na integração : )
cmd/api.go
Outdated
uri := os.Getenv("DATABASE_URL") | ||
if strings.HasPrefix(uri, "mongodb://") { | ||
mdb, _ := db.NewMongoDB(mongoDatabase) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer mdb.Close() | ||
api.Serve(&mdb, port, nr) | ||
|
||
} else if strings.HasPrefix(uri, "postgres://") || strings.HasPrefix(uri, "postgresql://") { | ||
pg, err := db.NewPostgreSQL(u, postgresSchema, nr) | ||
if err != nil { | ||
return err | ||
} | ||
defer pg.Close() | ||
|
||
api.Serve(&pg, port, nr) | ||
} else { | ||
return fmt.Errorf("unsupported database URI, must start with postgres:// or mongodb://") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bem melhor : ) Mas ainda dá para evitar repetição usando a interface, algo como:
var db database
} else if strings.HasPrefix(uri, "postgres://") || strings.HasPrefix(uri, "postgresql://") {
db = postgres{DATABASE_URL}
} else if strings.HasPrefix(uri, "mongodb://") {
db = mongoDb{DATABASE_URL}
} else {
// ...
}
err := api.Server(db)
if err != nil {
fmt.Println("Error:", err)
}
Fiz um exemplo executável se ajudar: https://go.dev/play/p/RAYi89lY1oi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cuducos eu ainda fico meio confuso com a integraçaão do golang com interfaces, entao eu por enquanto estou estudando mais essa minha deficiencia para retormar. enquanto isso tirei as linhas vazias.
vou retomar essa estrutura mais enxuta depois dos estudos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E, finalmente tive tempo de revisar o mongodb.go
— deixei alguns comentários, nada complicado, está bem bom!
Caso inglês seja uma barreira, deixe uns // TODO: translate
q eu dou um tapa depois!
cmd/api.go
Outdated
|
||
uri := os.Getenv("DATABASE_URL") | ||
if strings.HasPrefix(uri, "mongodb://") { | ||
mdb, _ := db.NewMongoDB(uri) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defer mdb.Close() | ||
api.Serve(&mdb, port, nr) | ||
|
||
} else if strings.HasPrefix(uri, "postgres://") || strings.HasPrefix(uri, "postgresql://") { | ||
pg, err := db.NewPostgreSQL(u, postgresSchema, nr) | ||
if err != nil { | ||
return err | ||
} | ||
defer pg.Close() | ||
|
||
api.Serve(&pg, port, nr) | ||
} else { | ||
return fmt.Errorf("unsupported database URI, must start with postgres:// or mongodb://") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essa implementação precisa mudar usando a interface, para evitar repetição.
cmd/cmd.go
Outdated
if strings.HasPrefix(uri, "mongodb://") { | ||
mdb, err := db.NewMongoDB(uri) | ||
if err != nil { | ||
return err | ||
} | ||
err = mdb.CreateCollection() | ||
if err != nil { | ||
return err | ||
} | ||
err = mdb.CreateIndexes() | ||
if err != nil { | ||
return err | ||
} | ||
defer mdb.Close() | ||
return err | ||
} else if strings.HasPrefix(uri, "postgres://") || strings.HasPrefix(uri, "postgresql://") { | ||
pg, err := db.NewPostgreSQL(u, postgresSchema, nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer pg.Close() | ||
return pg.CreateTable() | ||
} else { | ||
return fmt.Errorf("A URL não contém 'mongodb' nem 'postgres'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essa implementação precisa mudar usando a interface, para evitar repetição.
cmd/cmd.go
Outdated
uri := os.Getenv("DATABASE_URL") | ||
if strings.HasPrefix(uri, "mongodb://") { | ||
mdb, err := db.NewMongoDB(uri) | ||
if err != nil { | ||
return err | ||
} | ||
err = mdb.DropCollection() | ||
if err != nil { | ||
return err | ||
} | ||
return err | ||
} else if strings.HasPrefix(uri, "postgres://") || strings.HasPrefix(uri, "postgresql://") { | ||
pg, err := db.NewPostgreSQL(u, postgresSchema, nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer pg.Close() | ||
return pg.DropTable() | ||
} else { | ||
return fmt.Errorf("A URL não contém 'mongodb' nem 'postgres'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essa implementação precisa mudar usando a interface, para evitar repetição.
cmd/transform.go
Outdated
if cleanUp { | ||
if err := pg.DropTable(); err != nil { | ||
uri := os.Getenv("DATABASE_URL") | ||
if strings.HasPrefix(uri, "mongodb://") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Essa implementação precisa mudar usando a interface, para evitar repetição.
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
Co-authored-by: Eduardo Cuducos <[email protected]>
insert in mongo working fix interface testes mongodb consulta updated e o cnpj ja funcionando no mongo. restaurando o github url original fixes defer and recover debugs falta de conhecimento talvez? removido os debugs fixes ajustes solicitados fix aplicando mesmo padrao mais fixes alguns fixes fix PR traducao fixes exportei company, partenerData e cnae mudança no createIndex para o PostLoad e algumas traducoes retirado linhas vazias e nao ter necessidade da uri novamente refix translate and remove lines Update .env.sample Co-authored-by: Eduardo Cuducos <[email protected]> new fixes CreateCompanies golang mod tentativa de resolver conflitos tentando corrigir conflito variavel repetida fix again removing snappy novo go.mod e go.sum para o conflict Revert "novo go.mod e go.sum para o conflict" This reverts commit b0bc749. Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]> Update db/mongodb.go Co-authored-by: Eduardo Cuducos <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O programa não compila por um erro de import
cíclico, está na CI.
Localmente vc pode tentar com:
$ go test --race ./...
# github.com/cuducos/minha-receita/transform
package github.com/cuducos/minha-receita/transform
imports github.com/cuducos/minha-receita/db
imports github.com/cuducos/minha-receita/transform: import cycle not allowed in tes
Me parece q o múdulo transform depende de db
e o módulo db
depende do transform
. Isso não pode. Lembro que sugeri num comentário:
Se quiser criar um módulo models com ele, pode ser um opção…
Não sei se é esse o caso, mas não consegui aprofundar ainda.
Adicionado o uso do MongoDB no projeto. Ainda falta terminar as documentações
See #72