forked from silasdavis/modl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace most of the hook system with a simpler one that uses interfac…
…es to pre-calculate hook support and uses a lot less reflect
- Loading branch information
Showing
6 changed files
with
142 additions
and
48 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
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,52 @@ | ||
package gorp | ||
|
||
import ( | ||
"reflect" | ||
) | ||
|
||
type PreInserter interface { | ||
PreInsert(SqlExecutor) error | ||
} | ||
|
||
type PostInserter interface { | ||
PostInsert(SqlExecutor) error | ||
} | ||
|
||
type PostGetter interface { | ||
PostGet(SqlExecutor) error | ||
} | ||
|
||
type PreUpdater interface { | ||
PreUpdate(SqlExecutor) error | ||
} | ||
|
||
type PostUpdater interface { | ||
PostUpdate(SqlExecutor) error | ||
} | ||
|
||
type PreDeleter interface { | ||
PreDelete(SqlExecutor) error | ||
} | ||
|
||
type PostDeleter interface { | ||
PostDelete(SqlExecutor) error | ||
} | ||
|
||
// Determine which hooks are supported by the mapper struct i | ||
func (t *TableMap) setupHooks(i interface{}) { | ||
// These hooks must be implemented on a pointer, so if a value is passed in | ||
// we have to get a pointer for a new value of that type in order for the | ||
// type assertions to pass. | ||
ptr := i | ||
if reflect.ValueOf(i).Kind() == reflect.Struct { | ||
ptr = reflect.New(reflect.ValueOf(i).Type()).Interface() | ||
} | ||
|
||
_, t.CanPreInsert = ptr.(PreInserter) | ||
_, t.CanPostInsert = ptr.(PostInserter) | ||
_, t.CanPostGet = ptr.(PostGetter) | ||
_, t.CanPreUpdate = ptr.(PreUpdater) | ||
_, t.CanPostUpdate = ptr.(PostUpdater) | ||
_, t.CanPreDelete = ptr.(PreDeleter) | ||
_, t.CanPostDelete = ptr.(PostDeleter) | ||
} |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
set -e | ||
|
||
export GORP_TEST_DSN=gorptest/gorptest/gorptest | ||
export GORP_TEST_DIALECT=mysql | ||
export GORP_TEST_DSN="gorptest/gorptest/" | ||
export GORP_TEST_DIALECT="mysql" | ||
go test | ||
|
||
export GORP_TEST_DSN="user=gorptest password=gorptest dbname=gorptest sslmode=disable" | ||
export GORP_TEST_DIALECT=postgres | ||
export GORP_TEST_DSN="user=$USER dbname=gorptest sslmode=disable" | ||
export GORP_TEST_DIALECT="postgres" | ||
go test | ||
|
||
export GORP_TEST_DSN=/tmp/gorptest.bin | ||
export GORP_TEST_DIALECT=sqlite | ||
export GORP_TEST_DSN="/tmp/gorptest.bin" | ||
export GORP_TEST_DIALECT="sqlite" | ||
go test |
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,6 @@ | ||
- replace hook calling process with one that uses interfaces and reflect.CanInterface | ||
- remove list return support | ||
- replace reflect struct filling with structscan | ||
- cache/store as much reflect stuff as possible | ||
- add query builder | ||
|