Files
pgson/schema/table.go
2025-11-06 16:44:28 +01:00

44 lines
953 B
Go

package schema
import (
"encoding/json"
)
type Table struct {
Name string `json:"table"`
PrimaryKey string `json:"primary_key"`
Schema []Field `json:"schema"`
}
type Field struct {
Name string `json:"name"`
Type string `json:"type"`
Nullable *bool `json:"nullable"`
Default *string `json:"default"`
Unique *bool `json:"unique"`
Primary *bool `json:"primary"`
Comment *string `json:"comment"`
References *Reference `json:"references"`
Algorithm *string `json:"algorithm"`
}
type Reference struct {
Table string `json:"table"`
Column string `json:"column"`
OnDelete string `json:"on_delete"`
OnUpdate string `json:"on_update"`
}
func NewTable(data []byte) (*Table, error) {
var table Table
err := json.Unmarshal(data, &table)
if err != nil {
return nil, err
}
return &table, nil
}
func (t *Table) JSON() ([]byte, error) {
return json.Marshal(t)
}