Add basic, tailored SQL ORM mapper

This commit is contained in:
Patrick Pacher 2022-03-16 20:37:57 +01:00
parent f135ec3242
commit 62ec170b90
No known key found for this signature in database
GPG key ID: E8CD2DA160925A6D
9 changed files with 1669 additions and 63 deletions

View file

@ -0,0 +1,41 @@
package orm
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_SchemaBuilder(t *testing.T) {
cases := []struct {
Name string
Model interface{}
ExpectedSQL string
}{
{
"Simple",
struct {
ID int `sqlite:"id,primary,autoincrement"`
Text string `sqlite:"text,nullable"`
Int *int `sqlite:",not-null"`
Float interface{} `sqlite:",float,nullable"`
}{},
`CREATE TABLE Simple ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, text TEXT, Int INTEGER NOT NULL, Float REAL );`,
},
{
"Varchar",
struct {
S string `sqlite:",varchar(10)"`
}{},
`CREATE TABLE Varchar ( S VARCHAR(10) NOT NULL );`,
},
}
for idx := range cases {
c := cases[idx]
res, err := GenerateTableSchema(c.Name, c.Model)
assert.NoError(t, err)
assert.Equal(t, c.ExpectedSQL, res.CreateStatement(false))
}
}