storage/sql: add a SQL storage implementation

This change adds support for SQLite3, and Postgres.
This commit is contained in:
Eric Chiang
2016-09-14 18:11:57 -07:00
committed by Eric Chiang
parent 82a55cf785
commit 87a7d093b2
10 changed files with 1116 additions and 0 deletions

55
storage/sql/sql_test.go Normal file
View File

@@ -0,0 +1,55 @@
package sql
import "testing"
func TestTranslate(t *testing.T) {
tests := []struct {
testCase string
flavor flavor
query string
exp string
}{
{
"sqlite3 query bind replacement",
flavorSQLite3,
`select foo from bar where foo.zam = $1;`,
`select foo from bar where foo.zam = ?;`,
},
{
"sqlite3 query bind replacement at newline",
flavorSQLite3,
`select foo from bar where foo.zam = $1`,
`select foo from bar where foo.zam = ?`,
},
{
"sqlite3 query true",
flavorSQLite3,
`select foo from bar where foo.zam = true`,
`select foo from bar where foo.zam = 1`,
},
{
"sqlite3 query false",
flavorSQLite3,
`select foo from bar where foo.zam = false`,
`select foo from bar where foo.zam = 0`,
},
{
"sqlite3 bytea",
flavorSQLite3,
`"connector_data" bytea not null,`,
`"connector_data" blob not null,`,
},
{
"sqlite3 now",
flavorSQLite3,
`now(),`,
`date('now'),`,
},
}
for _, tc := range tests {
if got := tc.flavor.translate(tc.query); got != tc.exp {
t.Errorf("%s: want=%q, got=%q", tc.testCase, tc.exp, got)
}
}
}