Skip to content

Commit

Permalink
lots of gorp -> modl renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jmoiron committed Jun 2, 2013
1 parent 4397c37 commit 7d2142f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
14 changes: 7 additions & 7 deletions dbmap.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
//
package gorp
package modl

import (
"bytes"
Expand All @@ -13,14 +13,14 @@ import (
"strings"
)

// DbMap is the root gorp mapping object. Create one of these for each
// DbMap is the root modl mapping object. Create one of these for each
// database schema you wish to map. Each DbMap contains a list of
// mapped tables.
//
// Example:
//
// dialect := gorp.MySQLDialect{"InnoDB", "UTF8"}
// dbmap := &gorp.DbMap{Db: db, Dialect: dialect}
// dialect := modl.MySQLDialect{"InnoDB", "UTF8"}
// dbmap := &modl.DbMap{Db: db, Dialect: dialect}
//
type DbMap struct {
// Db handle to use with this map
Expand All @@ -45,7 +45,7 @@ func NewDbMap(db *sql.DB, dialect Dialect) *DbMap {
// a non-empty string, it will be written to the front of all logged
// strings, which can aid in filtering log lines.
//
// Use TraceOn if you want to spy on the SQL statements that gorp
// Use TraceOn if you want to spy on the SQL statements that modl
// generates.
func (m *DbMap) TraceOn(prefix string, logger *log.Logger) {
m.logger = logger
Expand All @@ -62,7 +62,7 @@ func (m *DbMap) TraceOff() {
m.logPrefix = ""
}

// AddTable registers the given interface type with gorp. The table name
// AddTable registers the given interface type with modl. The table name
// will be given the name of the TypeOf(i), lowercased.
//
// This operation is idempotent. If i's type is already mapped, the
Expand Down Expand Up @@ -300,7 +300,7 @@ func (m *DbMap) Exec(query string, args ...interface{}) (sql.Result, error) {
return m.Db.Exec(query, args...)
}

// Begin starts a gorp Transaction
// Begin starts a modl Transaction
func (m *DbMap) Begin() (*Transaction, error) {
tx, err := m.Dbx.Beginx()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion dialect.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gorp
package modl

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion hooks.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gorp
package modl

import (
"reflect"
Expand Down
22 changes: 10 additions & 12 deletions gorp.go → modl.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// Changes Copyright 2013 Jason Moiron. Original Gorp code
// Copyright 2012 James Cooper. All rights reserved.
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

// Package gorp provides a simple way to marshal Go structs to and from
// SQL databases. It uses the database/sql package, and should work with any
// compliant database/sql driver.
//
// Source code and project home:
// https://github.com/coopernurse/gorp
// https://github.com/jmoiron/modl
//
package gorp
package modl

import (
"bytes"
Expand All @@ -29,7 +27,7 @@ func (n NoKeysErr) Error() string {
return fmt.Sprintf("Could not find keys for table %v", n.Table)
}

var versFieldConst = "[gorp_ver_field]"
var versFieldConst = "[modl_ver_field]"

// OptimisticLockError is returned by Update() or Delete() if the
// struct being modified has a Version field and the value is not equal to
Expand All @@ -55,10 +53,10 @@ type OptimisticLockError struct {
// Error returns a description of the cause of the lock error
func (e OptimisticLockError) Error() string {
if e.RowExists {
return fmt.Sprintf("gorp: OptimisticLockError table=%s keys=%v out of date version=%d", e.TableName, e.Keys, e.LocalVersion)
return fmt.Sprintf("modl: OptimisticLockError table=%s keys=%v out of date version=%d", e.TableName, e.Keys, e.LocalVersion)
}

return fmt.Sprintf("gorp: OptimisticLockError no row found for table=%s keys=%v", e.TableName, e.Keys)
return fmt.Sprintf("modl: OptimisticLockError no row found for table=%s keys=%v", e.TableName, e.Keys)
}

// CustomScanner binds a database column value to a Go type
Expand All @@ -76,7 +74,7 @@ type CustomScanner struct {
Binder func(holder interface{}, target interface{}) error
}

// Bind is called automatically by gorp after Scan()
// Bind is called automatically by modl after Scan()
func (me CustomScanner) Bind() error {
return me.Binder(me.Holder, me.Target)
}
Expand Down Expand Up @@ -472,7 +470,7 @@ func (c *ColumnMap) SetMaxSize(size int) *ColumnMap {
return c
}

// SqlExecutor exposes gorp operations that can be run from Pre/Post
// SqlExecutor exposes modl operations that can be run from Pre/Post
// hooks. This hides whether the current operation that triggered the
// hook is in a transaction.
//
Expand Down Expand Up @@ -792,7 +790,7 @@ func insert(m *DbMap, exec SqlExecutor, list ...interface{}) error {
if (k == reflect.Int) || (k == reflect.Int16) || (k == reflect.Int32) || (k == reflect.Int64) {
f.SetInt(id)
} else {
return errors.New(fmt.Sprintf("gorp: Cannot set autoincrement value on non-Int field. SQL=%s autoIncrIdx=%d", bi.query, bi.autoIncrIdx))
return errors.New(fmt.Sprintf("modl: Cannot set autoincrement value on non-Int field. SQL=%s autoIncrIdx=%d", bi.query, bi.autoIncrIdx))
}
} else {
_, err := exec.Exec(bi.query, bi.args...)
Expand Down
14 changes: 7 additions & 7 deletions gorp_test.go → modl_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gorp
package modl

import (
"database/sql"
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestCreateTablesIfNotExists(t *testing.T) {
func TestPersistentUser(t *testing.T) {
dbmap := newDbMap()
dbmap.Exec("drop table if exists persistentuser")
//dbmap.TraceOn("", log.New(os.Stdout, "gorptest: ", log.Lmicroseconds))
//dbmap.TraceOn("", log.New(os.Stdout, "modltest: ", log.Lmicroseconds))
dbmap.AddTable(PersistentUser{}).SetKeys(false, "mykey")
err := dbmap.CreateTablesIfNotExists()
if err != nil {
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestNullValues(t *testing.T) {

func TestColumnProps(t *testing.T) {
dbmap := newDbMap()
//dbmap.TraceOn("", log.New(os.Stdout, "gorptest: ", log.Lmicroseconds))
//dbmap.TraceOn("", log.New(os.Stdout, "modltest: ", log.Lmicroseconds))
t1 := dbmap.AddTable(Invoice{}).SetKeys(true, "Id")
//t1.ColMap("Created").Rename("date_created")
t1.ColMap("Updated").SetTransient(true)
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestVersionMultipleRows(t *testing.T) {

func TestWithStringPk(t *testing.T) {
dbmap := newDbMap()
//dbmap.TraceOn("", log.New(os.Stdout, "gorptest: ", log.Lmicroseconds))
//dbmap.TraceOn("", log.New(os.Stdout, "modltest: ", log.Lmicroseconds))
dbmap.AddTableWithName(WithStringPk{}, "string_pk_test").SetKeys(true, "Id")
_, err := dbmap.Exec("create table string_pk_test (Id varchar(255), Name varchar(255));")
if err != nil {
Expand Down Expand Up @@ -651,7 +651,7 @@ func BenchmarkGorpCrud(b *testing.B) {
b.StopTimer()
dbmap := initDbMapBench()
defer dbmap.DropTables()
//dbmap.TraceOn("", log.New(os.Stdout, "gorptest: ", log.Lmicroseconds))
//dbmap.TraceOn("", log.New(os.Stdout, "modltest: ", log.Lmicroseconds))
b.StartTimer()

inv := &Invoice{0, 100, 200, "my memo", 0, true}
Expand Down Expand Up @@ -697,7 +697,7 @@ func initDbMapBench() *DbMap {

func initDbMap() *DbMap {
dbmap := newDbMap()
//dbmap.TraceOn("", log.New(os.Stdout, "gorptest: ", log.Lmicroseconds))
//dbmap.TraceOn("", log.New(os.Stdout, "modltest: ", log.Lmicroseconds))
dbmap.AddTableWithName(Invoice{}, "invoice_test").SetKeys(true, "id")
dbmap.AddTableWithName(Person{}, "person_test").SetKeys(true, "id")
dbmap.AddTableWithName(WithIgnoredColumn{}, "ignored_column_test").SetKeys(true, "id")
Expand All @@ -711,7 +711,7 @@ func initDbMap() *DbMap {

func initDbMapNulls() *DbMap {
dbmap := newDbMap()
//dbmap.TraceOn("", log.New(os.Stdout, "gorptest: ", log.Lmicroseconds))
//dbmap.TraceOn("", log.New(os.Stdout, "modltest: ", log.Lmicroseconds))
dbmap.AddTable(TableWithNull{}).SetKeys(false, "id")
err := dbmap.CreateTables()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions sql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gorp_test
package modl_test

import (
"database/sql"
Expand All @@ -16,11 +16,11 @@ func connectDb() *sql.DB {

// This fails on my machine with:
//
// panic: Received #1461 error from MySQL server:
// "Can't create more than max_prepared_stmt_count statements
// panic: Received #1461 error from MySQL server:
// "Can't create more than max_prepared_stmt_count statements
// (current value: 16382)"
//
// Cause: stmt.Exec() is opening a new db connection for each call
// Cause: stmt.Exec() is opening a new db connection for each call
// because each connection is still considered in use
//
func _TestPrepareExec(t *testing.T) {
Expand Down

0 comments on commit 7d2142f

Please sign in to comment.