Initialize the tests

This commit is contained in:
Jinzhu 2013-10-25 22:31:56 +08:00
parent b4031e004a
commit 7f9d486d5a
4 changed files with 35 additions and 10 deletions

3
Guardfile Normal file
View File

@ -0,0 +1,3 @@
guard 'gotest' do
watch(%r{\.go$})
end

13
main.go
View File

@ -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
View File

@ -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
} }

17
orm_test.go Normal file
View File

@ -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)
}