- mssql: write computed columns (AS (expr) PERSISTED) and identity; read computed definition and identity - sqlite: write GENERATED ALWAYS AS (expr) STORED; read generated columns via table_xinfo and parse the expression - drizzle: generatedAlwaysAs / generated(Always|ByDefault)AsIdentity, read and write - typeorm: asExpression/generatedType and identity decorators, read and write; decorator scan is now quote-aware - bun, gorm readers: read generated and identity markers - readmes updated
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package gorm
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git.warky.dev/wdevs/relspecgo/pkg/readers"
|
|
)
|
|
|
|
func TestReader_GeneratedAndIdentityMarkers(t *testing.T) {
|
|
src := `package models
|
|
|
|
type Person struct {
|
|
ID int64 ` + "`gorm:\"column:id;primaryKey;autoIncrement;type:bigint;identity\"`" + `
|
|
Seq int64 ` + "`gorm:\"column:seq;type:bigint;<-:false;identity;not null\"`" + `
|
|
FullName string ` + "`gorm:\"column:full_name;type:text;<-:false;generated\"`" + `
|
|
First string ` + "`gorm:\"column:first;type:text\"`" + `
|
|
}
|
|
|
|
func (Person) TableName() string {
|
|
return "people"
|
|
}
|
|
`
|
|
path := filepath.Join(t.TempDir(), "person.go")
|
|
if err := os.WriteFile(path, []byte(src), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
db, err := NewReader(&readers.ReaderOptions{FilePath: path}).ReadDatabase()
|
|
if err != nil {
|
|
t.Fatalf("ReadDatabase() error = %v", err)
|
|
}
|
|
cols := db.Schemas[0].Tables[0].Columns
|
|
|
|
if !cols["id"].Identity || cols["id"].IdentityGeneration != "ALWAYS" {
|
|
t.Errorf("id: identity = %v/%q, want true/ALWAYS", cols["id"].Identity, cols["id"].IdentityGeneration)
|
|
}
|
|
if !cols["seq"].Identity {
|
|
t.Error("seq should be identity")
|
|
}
|
|
if !cols["full_name"].Generated {
|
|
t.Error("full_name should be generated")
|
|
}
|
|
if cols["first"].Generated || cols["first"].Identity {
|
|
t.Error("first must be an ordinary column")
|
|
}
|
|
}
|