-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved query and exec process to Relation.
- Loading branch information
1 parent
75e5aa9
commit 4ed96a8
Showing
18 changed files
with
212 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ar | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/monochromegane/argen/query" | ||
) | ||
|
||
type Delete struct { | ||
*query.Delete | ||
exec *Executer | ||
} | ||
|
||
func NewDelete(db *sql.DB, logger *Logger) *Delete { | ||
return &Delete{ | ||
Delete: &query.Delete{}, | ||
exec: &Executer{db, logger}, | ||
} | ||
} | ||
|
||
func (d *Delete) Table(table string) *Delete { | ||
d.Delete.Table(table) | ||
return d | ||
} | ||
|
||
func (d *Delete) Where(cond string, args ...interface{}) *Delete { | ||
d.Delete.Where(cond, args...) | ||
return d | ||
} | ||
|
||
func (d *Delete) And(cond string, args ...interface{}) *Delete { | ||
return d.Where(cond, args...) | ||
} | ||
|
||
func (d *Delete) Exec() (sql.Result, error) { | ||
q, b := d.Delete.Build() | ||
return d.exec.Exec(q, b...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ar | ||
|
||
import ( | ||
"database/sql" | ||
"time" | ||
) | ||
|
||
type Executer struct { | ||
db *sql.DB | ||
logger *Logger | ||
} | ||
|
||
func (e *Executer) Exec(q string, b ...interface{}) (sql.Result, error) { | ||
defer e.log(time.Now(), q, b...) | ||
return e.db.Exec(q, b...) | ||
} | ||
|
||
func (e *Executer) log(t time.Time, sql string, args ...interface{}) { | ||
e.logger.Print(time.Now().Sub(t), sql, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ar | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/monochromegane/argen/query" | ||
) | ||
|
||
type Insert struct { | ||
*query.Insert | ||
exec *Executer | ||
} | ||
|
||
func NewInsert(db *sql.DB, logger *Logger) *Insert { | ||
return &Insert{ | ||
Insert: &query.Insert{}, | ||
exec: &Executer{db, logger}, | ||
} | ||
} | ||
|
||
func (i *Insert) Table(table string) *Insert { | ||
i.Insert.Table(table) | ||
return i | ||
} | ||
|
||
func (i *Insert) Params(params map[string]interface{}) *Insert { | ||
i.Insert.Params(params) | ||
return i | ||
} | ||
|
||
func (i *Insert) Exec() (sql.Result, error) { | ||
q, b := i.Insert.Build() | ||
return i.exec.Exec(q, b...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.