Update services.go, add MSSQL database connection to services.go#20
Update services.go, add MSSQL database connection to services.go#20ronydahdal wants to merge 13 commits intomainfrom
Conversation
|
I'm getting a couple errors in my VSCode, could you check this out?: |
jumarmartin
left a comment
There was a problem hiding this comment.
please look at the comment previous to this!
|
Seems like Main.go's paramaters haven't been updated to account for the new mssql connection, will push a commit to update main.go |
Backbones of ODS's migration from Elon's MSSQL Database into the ODS PostgreSQL Database
jumarmartin
left a comment
There was a problem hiding this comment.
Great second look! I added some comments that should help steer you in the right direction.
Some logistical notes: try to also update the docker-compse.yaml which should help with testing!
I do have another branch that has the changes included if you'd like me to commit that.
| // empty _ because Exec returns both a sql result obj & err value | ||
| // we're evaluating err value, hence the _ | ||
| _, err = pgConn.Exec(` | ||
| CREATE TABLE elonbuildingspg ( |
There was a problem hiding this comment.
We probably shouldn't concern our code with the creation of tables, just the connection itself and possibly pulling from it?
|
|
||
| for mssqlRows.Next() { | ||
| // declaration of variables to hold values of each column in row | ||
| var buildings_id string |
There was a problem hiding this comment.
Could we make this into a struct? It looks like we reuse this in the future.
There was a problem hiding this comment.
you're right, makes most sense to have it as a struct rather than keep redefining it, we can also use this struct in the json encoder file.
backend/service/services.go
Outdated
| "context" | ||
|
|
||
|
|
||
| "github.com/denisenkom/go-mssqldb" |
There was a problem hiding this comment.
| "github.com/denisenkom/go-mssqldb" | |
| mssql "github.com/denisenkom/go-mssqldb" |
| Logger *logrus.Logger | ||
| Db *pgx.Conn | ||
| PgDb *pgx.Conn | ||
| MsDb *mssql.DB |
There was a problem hiding this comment.
| MsDb *mssql.DB | |
| PgDb *pgx.Conn |
backend/service/services.go
Outdated
| @@ -15,7 +15,8 @@ package service | |||
|
|
|||
| import ( | |||
| "context" | |||
There was a problem hiding this comment.
| "context" | |
| "database/sql/driver" |
backend/service/services.go
Outdated
| return connection | ||
| } | ||
|
|
||
| func InitMsDB(msdbURL string, log *logrus.Logger) *mssql.DB { |
There was a problem hiding this comment.
| func InitMsDB(msdbURL string, log *logrus.Logger) *mssql.DB { | |
| func InitMsDB(msdbURL string, log *logrus.Logger) *driver.Conn { |
backend/main.go
Outdated
| // get our pertinent information from the environment variables or the command line | ||
| servicePort := flag.String("port", os.Getenv("PORT"), "port to run server on") | ||
| databaseURL := flag.String("database_url", os.Getenv("DATABASE_URL"), "database url") | ||
| postgresURL := flag.String("postgres_url", os.Getenv("POSTGRES_URL"), "postgres url") |
There was a problem hiding this comment.
Our database, in the future, could be anything! In future PRs we will abstract away from using pgx in initializing the database and instead just require whatever database someone uses to conform an interface.
| postgresURL := flag.String("postgres_url", os.Getenv("POSTGRES_URL"), "postgres url") | |
| databaseURL := flag.String("database_url", os.Getenv("DATABASE_URL"), "database url") |
backend/main.go
Outdated
| if *postgresURL == "" { | ||
| log.Fatal("postgres url not set") |
There was a problem hiding this comment.
| if *postgresURL == "" { | |
| log.Fatal("postgres url not set") | |
| if *databaseURL == "" { | |
| log.Fatal("database url not set") |
|
|
||
| func migrate() { |
There was a problem hiding this comment.
Lets add a todo here.
| func migrate() { | |
| //TODO(@ronydahdal) finish :) | |
| func migrate() { |
There was a problem hiding this comment.
I recommend moving this to a folder that might be more suited for a one-off run.
|
It looks like Microsoft has forked the currently used mssql integration: https://github.com/microsoft/go-mssqldb. |
No description provided.