Skip to content

Commit 878727d

Browse files
committed
Added package docs. Added LICENSE file. Added a few TODO items.
1 parent 64c5a7f commit 878727d

File tree

4 files changed

+239
-35
lines changed

4 files changed

+239
-35
lines changed

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2012 James Cooper <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ not infrastructure.
2828
## TODO ##
2929

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

3335
## Examples ##

dialect.go

+20
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,32 @@ import (
55
"reflect"
66
)
77

8+
// The Dialect interface encapsulates behaviors that differ across
9+
// SQL databases. At present the Dialect is only used by CreateTables()
10+
// but this could change in the future
811
type Dialect interface {
12+
13+
// ToSqlType returns the SQL column type to use when creating a
14+
// table of the given Go Type. maxsize can be used to switch based on
15+
// size. For example, in MySQL []byte could map to BLOB, MEDIUMBLOB,
16+
// or LONGBLOB depending on the maxsize
917
ToSqlType(val reflect.Type, maxsize int) string
18+
19+
// string to append to primary key column definitions
1020
AutoIncrStr() string
21+
22+
// string to append to "create table" statement for vendor specific
23+
// table attributes
1124
CreateTableSuffix() string
1225
}
1326

27+
// Implementation of Dialect for MySQL databases.
1428
type MySQLDialect struct {
29+
30+
// Engine is the storage engine to use "InnoDB" vs "MyISAM" for example
1531
Engine string
32+
33+
// Encoding is the character encoding to use for created tables
1634
Encoding string
1735
}
1836

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

51+
// Returns auto_increment
3352
func (m MySQLDialect) AutoIncrStr() string {
3453
return "auto_increment"
3554
}
3655

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

0 commit comments

Comments
 (0)