1
0
mirror of https://github.com/DATA-DOG/go-sqlmock.git synced 2025-04-25 12:04:40 +02:00

Add go-sql-driver imports to make it easier to run the examples

This commit is contained in:
Theo 2019-02-27 17:04:14 +00:00
parent 7f7699b45e
commit 05afef726f
4 changed files with 15 additions and 4 deletions

View File

@ -32,17 +32,21 @@ See **.travis.yml** for supported **go** versions.
Different use case, is to functionally test with a real database - [go-txdb](https://github.com/DATA-DOG/go-txdb) Different use case, is to functionally test with a real database - [go-txdb](https://github.com/DATA-DOG/go-txdb)
all database related actions are isolated within a single transaction so the database can remain in the same state. all database related actions are isolated within a single transaction so the database can remain in the same state.
See implementation examples: See implementation examples:
- [blog API server](https://github.com/DATA-DOG/go-sqlmock/tree/master/examples/blog) - [blog API server](https://github.com/DATA-DOG/go-sqlmock/tree/master/examples/blog)
- [the same orders example](https://github.com/DATA-DOG/go-sqlmock/tree/master/examples/orders) - [the same orders example](https://github.com/DATA-DOG/go-sqlmock/tree/master/examples/orders)
### Something you may want to test ### Something you may want to test, assuming you use the [go-mysql-driver](https://github.com/go-sql-driver/mysql)
``` go ``` go
package main package main
import "database/sql" import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func recordStats(db *sql.DB, userID, productID int64) (err error) { func recordStats(db *sql.DB, userID, productID int64) (err error) {
tx, err := db.Begin() tx, err := db.Begin()

View File

@ -1,6 +1,10 @@
package main package main
import "database/sql" import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func recordStats(db *sql.DB, userID, productID int64) (err error) { func recordStats(db *sql.DB, userID, productID int64) (err error) {
tx, err := db.Begin() tx, err := db.Begin()

View File

@ -4,6 +4,8 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"net/http" "net/http"
_ "github.com/go-sql-driver/mysql"
) )
type api struct { type api struct {

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"github.com/kisielk/sqlstruct" "github.com/kisielk/sqlstruct"
_ "github.com/go-sql-driver/mysql"
) )
const ORDER_PENDING = 0 const ORDER_PENDING = 0