-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cue loader and experimental realm decoding
- Loading branch information
1 parent
d3f0335
commit d3b3e52
Showing
40 changed files
with
2,518 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package cuemod | ||
|
||
import ( | ||
"embed" | ||
"io" | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
//go:embed gen module.cue | ||
var cueModFS embed.FS | ||
|
||
// Copy copies the contents of the embedded cue.mod directory to the given path. | ||
func Copy(target string) (err error) { | ||
// ensurer directory is a cue.mod directory | ||
// maybe rethink this... | ||
if !strings.HasSuffix(target, "/cue.mod") { | ||
target = filepath.Join(target, "cue.mod") | ||
} | ||
|
||
if err = os.MkdirAll(target, 0755); err != nil { | ||
return err | ||
} | ||
|
||
matches, err := fs.Glob(cueModFS, "./*") | ||
if err != nil { | ||
return | ||
} | ||
|
||
for _, file := range matches { | ||
var stat fs.FileInfo | ||
stat, err = fs.Stat(cueModFS, file) | ||
if err != nil { | ||
return | ||
} | ||
|
||
if stat.IsDir() { | ||
err = copyDir(copyDirParams{ | ||
fsRoot: file, | ||
targetDir: target, | ||
}) | ||
} else { | ||
err = copyFile(copyFileParams{ | ||
embeddedFile: file, | ||
targetDir: target, | ||
}) | ||
} | ||
|
||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
return err | ||
} | ||
|
||
type copyDirParams struct { | ||
fsRoot string | ||
targetDir string | ||
} | ||
|
||
func copyDir(params copyDirParams) error { | ||
return fs.WalkDir(cueModFS, params.fsRoot, func(path string, d fs.DirEntry, _ error) (err error) { | ||
if d.IsDir() { | ||
return os.MkdirAll(filepath.Join(params.targetDir, path), 0755) | ||
} | ||
|
||
err = copyFile(copyFileParams{ | ||
embeddedFile: path, | ||
targetDir: params.targetDir, | ||
}) | ||
if err != nil { | ||
return | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
type copyFileParams struct { | ||
targetDir string | ||
embeddedFile string | ||
} | ||
|
||
func copyFile(params copyFileParams) (err error) { | ||
vf, err := cueModFS.Open(params.embeddedFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dst := filepath.Join(params.targetDir, params.embeddedFile) | ||
f, err := os.OpenFile(dst, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0755) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
_, err = io.Copy(f, vf) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cuemod | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestCopy(t *testing.T) { | ||
target, err := os.MkdirTemp("", "atlas") | ||
require.NoError(t, err) | ||
|
||
defer os.RemoveAll(target) | ||
|
||
err = Copy(target) | ||
require.NoError(t, err) | ||
require.FileExists(t, filepath.Join(target, "cue.mod/module.cue")) | ||
require.FileExists(t, filepath.Join(target, "cue.mod/gen/ariga.io/atlas/sql/schema/schema_go_gen.cue")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go ariga.io/atlas/schemahcl | ||
|
||
package schemahcl | ||
|
||
// blockVar is an HCL resource that defines an input variable to the Atlas DDL document. | ||
_#blockVar: { | ||
Name: string | ||
Description: string | ||
} | ||
|
||
_#varBlock: "variable" | ||
_#dataBlock: "data" | ||
_#localsBlock: "locals" | ||
_#forEachAttr: "for_each" | ||
_#eachRef: "each" | ||
_#varRef: "var" | ||
_#localRef: "local" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go ariga.io/atlas/schemahcl | ||
|
||
package schemahcl | ||
|
||
import "reflect" | ||
|
||
// Remainer is the interface that is implemented by types that can store | ||
// additional attributes and children resources. | ||
#Remainer: _ | ||
|
||
// DefaultExtension can be embedded in structs that need basic default behavior. | ||
// For instance, DefaultExtension implements Remainer, and has a private *Resource | ||
// field that can store additional attributes and children that do not match the | ||
// structs fields. | ||
#DefaultExtension: { | ||
Extra: #Resource | ||
} | ||
|
||
_#registry: [string]: _ | ||
|
||
_#fieldDesc: StructField: reflect.#StructField | ||
|
||
_#rtype: _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go ariga.io/atlas/schemahcl | ||
|
||
package schemahcl | ||
|
||
#Evaluator: _ | ||
|
||
#Marshaler: _ | ||
|
||
// addrRef maps addresses to their referenced resource. | ||
_#addrRef: {[string]: null | #Resource} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go ariga.io/atlas/schemahcl | ||
|
||
package schemahcl | ||
|
||
import "reflect" | ||
|
||
#Resource: { | ||
Name: string | ||
Qualifier: string | ||
Type: string | ||
Attrs: [...null | #Attr] @go(,[]*Attr) | ||
Children: [...null | #Resource] @go(,[]*Resource) | ||
} | ||
|
||
#Attr: K: string | ||
|
||
#Ref: V: string | ||
|
||
#RawExpr: X: string | ||
|
||
#TypeSpec: { | ||
// Name is the identifier for the type in an Atlas DDL document. | ||
Name: string | ||
|
||
// T is the database identifier for the type. | ||
T: string | ||
Attributes: [...null | #TypeAttr] @go(,[]*TypeAttr) | ||
|
||
// RType is the reflect.Type of the schema.Type used to describe the TypeSpec. | ||
// This field is optional and used to determine the TypeSpec in cases where the | ||
// schema.Type does not have a `T` field. | ||
RType: reflect.#Type | ||
} | ||
|
||
#TypeAttr: { | ||
// Name should be a snake_case of related the schema.Type struct field. | ||
Name: string | ||
Kind: reflect.#Kind | ||
Required: bool | ||
} | ||
|
||
#Type: { | ||
T: string | ||
Attrs: [...null | #Attr] @go(,[]*Attr) | ||
IsRef: bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go ariga.io/atlas/sql/migrate | ||
|
||
package migrate | ||
|
||
#Dir: _ | ||
|
||
#Formatter: _ | ||
|
||
#File: _ | ||
|
||
#HashFileName: "atlas.sum" | ||
|
||
// HashFile represents the integrity sum file of the migration dir. | ||
#HashFile: string | ||
|
||
// atlas:sum directive. | ||
_#directiveSum: "sum" | ||
_#sumModeIgnore: "ignore" | ||
|
||
// atlas:delimiter directive. | ||
_#directiveDelimiter: "delimiter" | ||
_#directivePrefixSQL: "-- " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go ariga.io/atlas/sql/migrate | ||
|
||
package migrate | ||
|
||
// Stmt represents a scanned statement text along with its | ||
// position in the file and associated comments group. | ||
#Stmt: { | ||
Pos: int | ||
Text: string | ||
Comments: [...string] @go(,[]string) | ||
} | ||
|
||
_#eos: -1 | ||
_#delimiter: ";" | ||
_#delimiterCmd: "delimiter" |
Oops, something went wrong.