forked from mirror/gorm
Initialize the tests
This commit is contained in:
parent
b4031e004a
commit
7f9d486d5a
13
main.go
13
main.go
|
@ -1,20 +1,23 @@
|
||||||
package gorm
|
package gorm
|
||||||
|
|
||||||
import "database/sql"
|
import (
|
||||||
|
"database/sql"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
Db *sql.DB
|
Db *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func Open(driver, source string) (db *DB, err error) {
|
func Open(driver, source string) (db DB, err error) {
|
||||||
db.Db, err = sql.Open(driver, source)
|
db.Db, err = sql.Open(driver, source)
|
||||||
// SetMaxIdleConns pools
|
// SetMaxIdleConns pools
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) buildORM() (orm *Orm) {
|
func (s *DB) buildORM() *Orm {
|
||||||
orm.Db = s.Db
|
orm := &Orm{db: s.Db}
|
||||||
return
|
return orm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) Where(querystring interface{}, args ...interface{}) (orm *Orm) {
|
func (s *DB) Where(querystring interface{}, args ...interface{}) (orm *Orm) {
|
||||||
|
|
12
orm.go
12
orm.go
|
@ -3,17 +3,19 @@ package gorm
|
||||||
import "database/sql"
|
import "database/sql"
|
||||||
|
|
||||||
type Orm struct {
|
type Orm struct {
|
||||||
Db *sql.DB
|
|
||||||
TableName string
|
TableName string
|
||||||
WhereStr string
|
|
||||||
OrderStr string
|
|
||||||
PrimaryKey string
|
PrimaryKey string
|
||||||
OffsetInt int64
|
|
||||||
LimitInt int64
|
|
||||||
Error bool
|
Error bool
|
||||||
|
|
||||||
|
db *sql.DB
|
||||||
|
whereClause []interface{}
|
||||||
|
orderStr string
|
||||||
|
offsetInt int64
|
||||||
|
limitInt int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Orm) Where(querystring interface{}, args ...interface{}) *Orm {
|
func (s *Orm) Where(querystring interface{}, args ...interface{}) *Orm {
|
||||||
|
s.whereClause = append(s.whereClause, map[string]interface{}{"query": querystring, "args": args})
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package gorm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWhere(t *testing.T) {
|
||||||
|
db, err := Open("postgres", "user=gorm dbname=gorm")
|
||||||
|
|
||||||
|
if err != err {
|
||||||
|
t.Errorf("Error should be nil")
|
||||||
|
}
|
||||||
|
orm := db.Where("id = $1", 1).Where("name = $1", "jinzhu")
|
||||||
|
fmt.Println(orm.whereClause)
|
||||||
|
}
|
Loading…
Reference in New Issue