Exemple #1
0
func ExampleConnect() {
	db := pg.Connect(&pg.Options{
		User: "******",
	})
	err := db.Close()
	fmt.Println(err)
	// Output: <nil>
}
Exemple #2
0
func (t *PoolTest) SetUpTest(c *C) {
	t.db = pg.Connect(&pg.Options{
		User:     "******",
		Database: "test",
		PoolSize: 10,

		DialTimeout:  time.Second,
		ReadTimeout:  time.Second,
		WriteTimeout: time.Second,
	})
}
Exemple #3
0
func ExampleDB_Query() {
	db := pg.Connect(&pg.Options{
		User: "******",
	})
	defer db.Close()

	users, err := GetUsers(db)
	fmt.Println(err)
	fmt.Println(users[0], users[1])
	// Output: <nil>
	// &{admin [admin1@admin admin2@admin]} &{root [root1@root root2@root]}
}
func Example_complexQuery() {
	db := pg.Connect(&pg.Options{
		User: "******",
	})
	defer db.Close()

	articles, err := GetArticles(db, &ArticleFilter{})
	fmt.Println(articles[0], articles[1], err)

	articles, err = GetArticles(db, &ArticleFilter{CategoryId: 1})
	fmt.Println(articles[0], err)

	// Output: &{article1 1} &{article2 2} <nil>
	// &{article1 1} <nil>
}
Exemple #5
0
func TestPgCon(t *testing.T) {

	var sifTests SifTests

	db := pg.Connect(&pg.Options{
		User: "******", Password: "******", Database: "bringout",
	})

	_, err := db.Query(&sifTests, `SELECT * FROM siftest`)

	for _, sifTest := range sifTests {
		fmt.Printf("Record# %s: %s\n", sifTest.Id, sifTest.Name)
	}
	err = db.Close()
	fmt.Println(err)

}
Exemple #6
0
func (t *DBTest) SetUpTest(c *C) {
	t.db = pg.Connect(&pg.Options{
		User:     "******",
		Database: "test",
		PoolSize: 2,

		DialTimeout:  time.Second,
		ReadTimeout:  time.Second,
		WriteTimeout: time.Second,
	})

	pqdb, err := sql.Open("postgres", "user=test dbname=test")
	c.Assert(err, IsNil)
	t.pqdb = pqdb

	mysqldb, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/test")
	c.Assert(err, IsNil)
	t.mysqldb = mysqldb
}
Exemple #7
0
func init() {
	db = pg.Connect(&pg.Options{
		User: "******",
	})
}