Skip to content

Commit

Permalink
Use lower case for log
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Nov 27, 2024
1 parent 3e341f4 commit 01b0a8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (d *txDriver) Open(dsn string) (driver.Conn, error) {
c, ok := d.conns[dsn]
if !ok {
c = &conn{dsn: dsn, drv: d, savepoints: []int{0}, log: d.log}
fmt.Fprintf(c.log, "%s: Open\n", c.dsn)
fmt.Fprintf(c.log, "%s: open\n", c.dsn)
c.tx, err = d.db.Begin()
d.conns[dsn] = c
}
Expand All @@ -177,7 +177,7 @@ func (c *conn) Close() (err error) {
c.tx = nil
delete(c.drv.conns, c.dsn)
}
fmt.Fprintf(c.log, "%s: Close\n", c.dsn)
fmt.Fprintf(c.log, "%s: close\n", c.dsn)
return
}

Expand All @@ -189,12 +189,12 @@ func (c *conn) Begin() (driver.Tx, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to create savepoint")
}
fmt.Fprintf(c.log, "%s: Begin\n", c.dsn)
fmt.Fprintf(c.log, "%s: begin\n", c.dsn)
return c, nil
}

func (c *conn) Commit() error {
fmt.Fprintf(c.log, "%s: Commit\n", c.dsn)
fmt.Fprintf(c.log, "%s: commit\n", c.dsn)
return nil
}

Expand All @@ -206,7 +206,7 @@ func (c *conn) Rollback() error {
if err != nil {
return errors.Wrap(err, "failed to rollback to savepoint")
}
fmt.Fprintf(c.log, "%s: Rollback\n", c.dsn)
fmt.Fprintf(c.log, "%s: rollback\n", c.dsn)
return nil
}

Expand All @@ -225,7 +225,7 @@ func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
c.Lock()
defer c.Unlock()

fmt.Fprintf(c.log, "%s: Exec %s\n", c.dsn, query)
fmt.Fprintf(c.log, "%s: exec %s\n", c.dsn, query)
return c.tx.Exec(query, mapArgs(args)...)
}

Expand Down Expand Up @@ -258,7 +258,7 @@ type stmt struct {
}

func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
fmt.Fprintf(s.log, "%s: Exec prepared statement\n", s.dsn)
fmt.Fprintf(s.log, "%s: exec prepared statement\n", s.dsn)
return s.st.Exec(mapArgs(args)...)
}

Expand Down Expand Up @@ -397,7 +397,7 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
c.Lock()
defer c.Unlock()

fmt.Fprintf(c.log, "%s: Exec %s\n", c.dsn, query)
fmt.Fprintf(c.log, "%s: exec %s\n", c.dsn, query)
return c.tx.ExecContext(ctx, query, mapNamedArgs(args)...)
}

Expand All @@ -410,7 +410,7 @@ func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e
if err != nil {
return nil, errors.Wrap(err, "failed to create savepoint")
}
fmt.Fprintf(c.log, "%s: BeginTx\n", c.dsn)
fmt.Fprintf(c.log, "%s: begin\n", c.dsn)
return c, nil
}

Expand All @@ -433,7 +433,7 @@ func (c *conn) Ping(ctx context.Context) error {

// Implement the "StmtExecContext" interface
func (s *stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
fmt.Fprintf(s.log, "%s: ExecContext prepared statement\n", s.dsn)
fmt.Fprintf(s.log, "%s: exec prepared statement\n", s.dsn)
return s.st.ExecContext(ctx, mapNamedArgs(args)...)
}

Expand Down
20 changes: 10 additions & 10 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func TestShouldRunWithinTransactionForOpenDB(t *testing.T) {
t.Fatalf("expected 1 user to be in database, but got %d", count)
}

expectedDb1Log := `one: Open
one: Exec INSERT INTO app_user(username, email) VALUES('txdb', '[email protected]')
expectedDb1Log := `one: open
one: exec INSERT INTO app_user(username, email) VALUES('txdb', '[email protected]')
`

if db1Log.String() != expectedDb1Log {
Expand All @@ -91,7 +91,7 @@ one: Exec INSERT INTO app_user(username, email) VALUES('txdb', '[email protected]')
t.Errorf("expected 0 user to be in database, but got %d", count)
}

expectedDb2Log := `two: Open
expectedDb2Log := `two: open
`

if db2Log.String() != expectedDb2Log {
Expand Down Expand Up @@ -263,13 +263,13 @@ func TestSavepointRollbackSequentialForOpenDB(t *testing.T) {
t.Errorf("expected 1 user with username taro, but got %d", count)
}

expectedDbLog := `one: Open
one: BeginTx
one: Exec INSERT INTO app_user(username, email) VALUES ('taro', '[email protected]')
one: Commit
one: BeginTx
one: Exec INSERT INTO app_user(username, email) VALUES ('taro', '[email protected]')
one: Rollback
expectedDbLog := `one: open
one: begin
one: exec INSERT INTO app_user(username, email) VALUES ('taro', '[email protected]')
one: commit
one: begin
one: exec INSERT INTO app_user(username, email) VALUES ('taro', '[email protected]')
one: rollback
`

if dbLog.String() != expectedDbLog {
Expand Down

0 comments on commit 01b0a8c

Please sign in to comment.