Пример #1
0
//StringToDialect returns an sql dialect for use with QBS given a string
//name.  IF the name is not known, this code panics.
func StringToDialect(n string) qbs.Dialect {
	switch n {
	case "postgres":
		return qbs.NewPostgres()
	case "sqlite3":
		return qbs.NewSqlite3()
	}
	panic(fmt.Sprintf("unable to deal with db dialect provided %s", n))
}
Пример #2
0
func SetMg() (mg *qbs.Migration, err error) {
	db, err := OpenDb(dbtypeset)

	switch {
	case dbtypeset == "sqlite":
		mg = qbs.NewMigration(db, DbName, qbs.NewSqlite3())
	case dbtypeset == "mysql":
		mg = qbs.NewMigration(db, DbName, qbs.NewMysql())
	case dbtypeset == "pgsql":
		mg = qbs.NewMigration(db, DbName, qbs.NewPostgres())

	}
	return mg, err
}
Пример #3
0
func init() {
	revel.OnAppStart(func() {
		var (
			found   bool
			spec    []string
			dialect qbs.Dialect
		)

		if Driver, found = revel.Config.String("db.driver"); !found {
			revel.ERROR.Fatal("No db.driver found.")
		}
		switch strings.ToLower(Driver) {
		case "mysql":
			dialect = qbs.NewMysql()
		case "postgres":
			dialect = qbs.NewPostgres()
		case "sqlite3":
			dialect = qbs.NewSqlite3()
		}

		// Start building the spec from available config options
		if User, found = revel.Config.String("db.user"); found {
			spec = append(spec, User)
			if Password, found = revel.Config.String("db.password"); found {
				spec = append(spec, fmt.Sprintf(":%v", Password))
			}
			spec = append(spec, "@")
		}
		if Protocol, found = revel.Config.String("db.protocol"); found {
			spec = append(spec, Protocol)
			if Address, found = revel.Config.String("db.address"); found {
				spec = append(spec, fmt.Sprintf("(%v)", Address))
			}
		}
		if DbName, found = revel.Config.String("db.dbname"); !found {
			revel.ERROR.Fatal("No db.dbname found.")
		}
		spec = append(spec, fmt.Sprintf("/%v", DbName))
		if Params, found = revel.Config.String("db.params"); found {
			spec = append(spec, fmt.Sprintf("?%v", Params))
		}

		qbs.Register(Driver, strings.Join(spec, ""), DbName, dialect)
		Db, err = qbs.GetQbs()
		defer Db.Close()
	})
}
Пример #4
0
Файл: k.go Проект: rose312/mzr
func main() {
	dsn := new(qbs.DataSourceName)
	dsn.Password = "******"
	dsn.Username = "******"
	dsn.DbName = "pgsql"
	dsn.Dialect = qbs.NewPostgres()
	qbs.RegisterWithDataSourceName(dsn)
	dsn.Append("sslmode", "disable")
	qbs.SetConnectionLimit(10, false)
	mg, err := qbs.GetMigration()
	if err != nil {
		fmt.Println(err)
	}
	mg.Log = true
	mg.CreateTableIfNotExists(new(Process))
	http.HandleFunc("/", do)
	http.ListenAndServe(":80", nil)
}
Пример #5
0
func ConnDb() (q *qbs.Qbs, err error) {
	db := qbs.GetFreeDB()
	if db == nil {
		db, err = OpenDb(dbtypeset)
		if err != nil {
			return nil, err
		}
	}

	switch {
	case dbtypeset == "sqlite":
		q = qbs.New(db, qbs.NewSqlite3())

	case dbtypeset == "mysql":
		q = qbs.New(db, qbs.NewMysql())

	case dbtypeset == "pgsql":
		q = qbs.New(db, qbs.NewPostgres())

	}
	return q, nil
}
Пример #6
0
func RegisterDb() {

	switch {
	case dbtypeset == "sqlite":
		qbs.Register("sqlite3", "./data/sqlite.db", "", qbs.NewSqlite3())

	case dbtypeset == "mysql":
		qbs.Register("mysql", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewMysql())

	case dbtypeset == "pgsql":
		qbs.Register("postgres", "user=postgres password=jn!@#$%^&* dbname=pgsql sslmode=disable", "pgsql", qbs.NewPostgres())
	}

}
Пример #7
0
func createTables() {
	qbs.Register("postgres", "user=holla dbname=hollaholla password=gimmiechocolate sslmode=disable", "hollaholla", qbs.NewPostgres())
	err := createTable(new(User))
	if err != nil {
		panic(err)
	}
	err = createTable(new(Store))
	if err != nil {
		panic(err)
	}
	err = createTable(new(Deal))
	if err != nil {
		panic(err)
	}
}
Пример #8
0
func RegisterDb() {

	switch {
	case dbtypeset == "sqlite":
		qbs.Register("sqlite3", "./data/sqlite.db", "", qbs.NewSqlite3())

	case dbtypeset == "mysql":
		qbs.Register("mysql", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewMysql())

	case dbtypeset == "pgsql":
		qbs.Register("postgres", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewPostgres())
	}

}
Пример #9
0
Файл: t2.go Проект: rose312/mzr
func main() {
	qbs.Register("postgres", "user=postgres password=jn!@#$%^&* dbname=pgsql sslmode=disable", "pgsql", qbs.NewPostgres())
	m, _ := qbs.GetMigration()
	//m.Log = true
	//m.DropTable(new(Topic))
	m.CreateTableIfNotExists(new(Topic))

	q, _ := qbs.GetQbs()
	//q.Log = true
	i := new(Topic)
	i.Content = "i am test!!!!!!"
	q.Save(i)

	nana, _ := FindNaById(q, 1)
	fmt.Println(nana)
}