17b77ed03370 — Peter Sanchez v0.1.0 2 years ago
Removing export of WithTx, it's not needed.
3 files changed, 6 insertions(+), 7 deletions(-)

M README.md
M migrate.go
M sql.go
M README.md +1 -1
@@ 1,4 1,4 @@ 
-# migrate
+# migrate [![godoc](https://godocs.io/petersanchez.com/migrate?status.svg)](https://godocs.io/petersanchez.com/migrate)
 
 Database migrations for your Go project. Supports files, functions, and query
 migrations.

          
M migrate.go +4 -4
@@ 181,7 181,7 @@ func (me *MigrationEngine) rebind(query 
 
 func (me *MigrationEngine) getRecord(ctx context.Context, id string) (string, error) {
 	var found string
-	err := WithTx(ctx, txOptionsRO, func(tx *sql.Tx) error {
+	err := withTx(ctx, txOptionsRO, func(tx *sql.Tx) error {
 		query := me.rebind("SELECT id FROM migrations WHERE id=?")
 		return tx.QueryRowContext(ctx, query, id).Scan(&found)
 	})

          
@@ 197,7 197,7 @@ func (me *MigrationEngine) printf(format
 }
 
 func (me *MigrationEngine) createMigrationTable(ctx context.Context) error {
-	err := WithTx(ctx, nil, func(tx *sql.Tx) error {
+	err := withTx(ctx, nil, func(tx *sql.Tx) error {
 		_, err := tx.ExecContext(ctx, "CREATE TABLE IF NOT EXISTS migrations (id TEXT PRIMARY KEY)")
 		if err != nil {
 			return fmt.Errorf("creating migrations table: %w", err)

          
@@ 216,7 216,7 @@ func (me *MigrationEngine) runMigration(
 		defer cancel()
 	}
 
-	err := WithTx(ctx, nil, func(tx *sql.Tx) error {
+	err := withTx(ctx, nil, func(tx *sql.Tx) error {
 		query := me.rebind("INSERT INTO migrations (id) VALUES (?)")
 		_, err := tx.ExecContext(ctx, query, m.ID)
 		if err != nil {

          
@@ 244,7 244,7 @@ func (me *MigrationEngine) runRollback(c
 		defer cancel()
 	}
 
-	err := WithTx(ctx, nil, func(tx *sql.Tx) error {
+	err := withTx(ctx, nil, func(tx *sql.Tx) error {
 		query := me.rebind("DELETE FROM migrations WHERE id=?")
 		_, err := tx.ExecContext(ctx, query, m.ID)
 		if err != nil {

          
M sql.go +1 -2
@@ 80,8 80,7 @@ func dbFromContext(ctx context.Context) 
 	return db
 }
 
-// WithTx calls a function wrapped in a database transaction
-func WithTx(ctx context.Context, opts *sql.TxOptions, fn func(tx *sql.Tx) error) error {
+func withTx(ctx context.Context, opts *sql.TxOptions, fn func(tx *sql.Tx) error) error {
 	db := dbFromContext(ctx)
 	tx, err := db.BeginTx(ctx, opts)
 	if err != nil {