gorm/main.go

79 lines
1.3 KiB
Go
Raw Normal View History

2013-10-25 14:04:48 +04:00
package gorm
import "database/sql"
type DB struct {
Db *sql.DB
}
func Open(driver, source string) (db *DB, err error) {
db.Db, err = sql.Open(driver, source)
2013-10-25 14:31:10 +04:00
// SetMaxIdleConns pools
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) buildORM() (orm *Orm) {
2013-10-25 14:04:48 +04:00
orm.Db = s.Db
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Where(querystring interface{}, args ...interface{}) (orm *Orm) {
orm = s.buildORM()
2013-10-25 14:04:48 +04:00
orm.Where(querystring, args)
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) First(out interface{}) (orm *Orm) {
orm = s.buildORM()
orm.First(out)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Find(out interface{}) (orm *Orm) {
orm = s.buildORM()
orm.Find(out)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Limit(value interface{}) (orm *Orm) {
orm = s.buildORM()
orm.Limit(value)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Offset(value interface{}) (orm *Orm) {
orm = s.buildORM()
orm.Offset(value)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Order(value interface{}) (orm *Orm) {
orm = s.buildORM()
orm.Order(value)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Select(querystring string) (orm *Orm) {
orm = s.buildORM()
orm.Select(querystring)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Save(value interface{}) (orm *Orm) {
orm = s.buildORM()
orm.Save(value)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Delete(value interface{}) (orm *Orm) {
orm = s.buildORM()
orm.Delete(value)
2013-10-25 14:04:48 +04:00
return
}
2013-10-25 14:31:10 +04:00
func (s *DB) Exec(sql string) (orm *Orm) {
orm = s.buildORM()
orm.Exec(sql)
2013-10-25 14:04:48 +04:00
return
}