feat: Change CreateSchemaFromJson to CreateSchema
This commit is contained in:
17
build/create.go
Normal file
17
build/create.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.secnex.io/secnex/pgson/schema"
|
||||
)
|
||||
|
||||
func Create(s *schema.Table) (string, error) {
|
||||
schemaParts := make([]string, len(s.Schema))
|
||||
for i, field := range s.Schema {
|
||||
schemaParts[i] = field.SQL()
|
||||
}
|
||||
query := fmt.Sprintf("CREATE TABLE %s (%s)", s.Name, strings.Join(schemaParts, ",\n"))
|
||||
return query, nil
|
||||
}
|
||||
2
pgson.go
2
pgson.go
@@ -14,6 +14,6 @@ func NewSchemaFromFile(path string) (*schema.Table, error) {
|
||||
return schema.NewTable(data)
|
||||
}
|
||||
|
||||
func NewSchemaFromJSON(json []byte) (*schema.Table, error) {
|
||||
func NewSchema(json []byte) (*schema.Table, error) {
|
||||
return schema.NewTable(json)
|
||||
}
|
||||
|
||||
13
query.go
Normal file
13
query.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package pgson
|
||||
|
||||
import (
|
||||
"git.secnex.io/secnex/pgson/build"
|
||||
"git.secnex.io/secnex/pgson/schema"
|
||||
)
|
||||
|
||||
func CreateSQL(s *schema.Table) (string, error) {
|
||||
if err := s.Validate(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return build.Create(s)
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package schema
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Table struct {
|
||||
@@ -96,15 +95,3 @@ func (f *Field) SQLReferences() string {
|
||||
}
|
||||
return fmt.Sprintf(" REFERENCES %s(%s)", f.References.Table, f.References.Column)
|
||||
}
|
||||
|
||||
func (t *Table) CreateSQL() (string, error) {
|
||||
if err := t.Validate(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
schemaParts := make([]string, len(t.Schema))
|
||||
for i, field := range t.Schema {
|
||||
schemaParts[i] = field.SQL()
|
||||
}
|
||||
query := fmt.Sprintf("CREATE TABLE %s (%s)", t.Name, strings.Join(schemaParts, ",\n"))
|
||||
return query, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user