Skip to content

Commit

Permalink
Added package docs. Added LICENSE file. Added a few TODO items.
Browse files Browse the repository at this point in the history
  • Loading branch information
coopernurse committed Jan 6, 2012
1 parent 64c5a7f commit 878727d
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 35 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2012 James Cooper <james@bitmechanic.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ not infrastructure.
## TODO ##

* BIG: Sort out NULL value mapping (see Issues below)
* Add tests for all exp/sql types: int64, int32, float64, []byte
* AddTable should return existing table if same interface is passed in
* Optional optimistic locking using a version column

## Examples ##
Expand Down
20 changes: 20 additions & 0 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,32 @@ import (
"reflect"
)

// The Dialect interface encapsulates behaviors that differ across
// SQL databases. At present the Dialect is only used by CreateTables()
// but this could change in the future
type Dialect interface {

// ToSqlType returns the SQL column type to use when creating a
// table of the given Go Type. maxsize can be used to switch based on
// size. For example, in MySQL []byte could map to BLOB, MEDIUMBLOB,
// or LONGBLOB depending on the maxsize
ToSqlType(val reflect.Type, maxsize int) string

// string to append to primary key column definitions
AutoIncrStr() string

// string to append to "create table" statement for vendor specific
// table attributes
CreateTableSuffix() string
}

// Implementation of Dialect for MySQL databases.
type MySQLDialect struct {

// Engine is the storage engine to use "InnoDB" vs "MyISAM" for example
Engine string

// Encoding is the character encoding to use for created tables
Encoding string
}

Expand All @@ -30,10 +48,12 @@ func (m MySQLDialect) ToSqlType(val reflect.Type, maxsize int) string {
return fmt.Sprintf("varchar(%d)", maxsize)
}

// Returns auto_increment
func (m MySQLDialect) AutoIncrStr() string {
return "auto_increment"
}

// Returns engine=%s charset=%s based on values stored on struct
func (m MySQLDialect) CreateTableSuffix() string {
return fmt.Sprintf(" engine=%s charset=%s", m.Engine, m.Encoding)
}
Loading

0 comments on commit 878727d

Please sign in to comment.