Skip to content

mm-matsuda/dbconfparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dbconfparser

Parse dbconf.yml to string.

Install

go get github.com/mm-matsuda/dbconfparser

Example

main.go

package main

import (
        "github.com/jinzhu/gorm"
        _ "github.com/jinzhu/gorm/dialects/mysql"
        "github.com/mm-matsuda/dbconfparser"
)

type Sample struct {
        Name string `json:"name"`
}

func main() {
        driver, open, err := dbconfparser.Parse("db/dbconf.yml", "test")
        if err != nil {
                panic(err)
        }
        db, err := gorm.Open(driver, open)
        if err != nil {
                panic(err)
        }

        sample := Sample{}
        sample.Name = "moo"
        db.First(&sample)
}

dbconf.yml

development:
  driver: mysql
  open: user:password@tcp(127.0.0.1:3306)/database_development?parseTime=true
test:
  driver: mysql
  open: user:password@tcp(127.0.0.1:3306)/database_test?parseTime=true

About

Parse dbconf.yml to string.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages