|
|
|
@ -1,15 +1,53 @@ |
|
|
|
|
package tests |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"database/sql" |
|
|
|
|
"testing" |
|
|
|
|
"fmt" |
|
|
|
|
"reflect" |
|
|
|
|
"log" |
|
|
|
|
"zedshaw.games/webapp/data" |
|
|
|
|
// _ "github.com/mattn/go-sqlite3"
|
|
|
|
|
// "github.com/jmoiron/sqlx"
|
|
|
|
|
_ "github.com/mattn/go-sqlite3" |
|
|
|
|
sq "github.com/Masterminds/squirrel" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func SelectTable1(table string, theType reflect.Type, err error, sql_query string, args ...interface{}) (error) { |
|
|
|
|
db, err := sql.Open("sqlite3", "./db.sqlite3") |
|
|
|
|
defer db.Close() |
|
|
|
|
|
|
|
|
|
rows, err := db.Query(sql_query, args...) |
|
|
|
|
if err != nil { log.Fatal(err) } |
|
|
|
|
defer rows.Close() |
|
|
|
|
|
|
|
|
|
for rows.Next() { |
|
|
|
|
data := make([]interface{}, theType.NumField()) |
|
|
|
|
columns := make([]interface{}, theType.NumField()) |
|
|
|
|
|
|
|
|
|
for i := 0; i < len(columns); i++ { |
|
|
|
|
columns[i] = &data[i] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
rows.Scan(columns...) |
|
|
|
|
|
|
|
|
|
fmt.Println(data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rows.Err() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func SelectTable2(theType reflect.Type, err error, sql_query string, args ...interface{}) (error) { |
|
|
|
|
|
|
|
|
|
the_data := reflect.New(theType) |
|
|
|
|
|
|
|
|
|
err = data.DB.Get(the_data.Interface(), sql_query, args...) |
|
|
|
|
|
|
|
|
|
fmt.Println("select after says", the_data) |
|
|
|
|
|
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestAdminIndexPage(t *testing.T) { |
|
|
|
|
|
|
|
|
|
models := data.Models() |
|
|
|
|
|
|
|
|
|
for table, model := range models { |
|
|
|
@ -19,5 +57,9 @@ func TestAdminIndexPage(t *testing.T) { |
|
|
|
|
for _, field := range fields { |
|
|
|
|
fmt.Println("\t", field.Name, field.Type, field.Tag) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sql, args, err := sq.Select("*").From(table).ToSql() |
|
|
|
|
err = SelectTable2(model, err, sql, args...) |
|
|
|
|
if err != nil { fmt.Println("ERROR", err) } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|