-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from chuckpreslar/v0.4
v0.4
- Loading branch information
Showing
8 changed files
with
261 additions
and
99 deletions.
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
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
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 |
---|---|---|
@@ -1,20 +1,21 @@ | ||
// Package nodes provides nodes to use in codex AST's. | ||
package nodes | ||
|
||
// AlterStatement is the base node for SQL Create and Alter Statements. | ||
type AlterStatementNode struct { | ||
Relation *RelationNode | ||
Columns []*UnexistingColumnNode | ||
Constraints []*ConstraintNode | ||
Engine *EngineNode | ||
Create bool | ||
Relation *RelationNode // The RelationNode the AlterStatementNode affects. | ||
Columns []*UnexistingColumnNode // Columns to create with the alteration. | ||
Constraints []interface{} // Constraints to apply with the alteration. | ||
Engine *EngineNode // Engine the table uses if created. | ||
Create bool // Is the AlterStatementNode creating a table based on the RelationNode. | ||
} | ||
|
||
// AlterStatementNode factory method. | ||
func AlterStatement(relation *RelationNode, create bool) (statement *AlterStatementNode) { | ||
statement = new(AlterStatementNode) | ||
statement.Relation = relation | ||
statement.Columns = make([]*UnexistingColumnNode, 0) | ||
statement.Constraints = make([]*ConstraintNode, 0) | ||
statement.Constraints = make([]interface{}, 0) | ||
statement.Create = create | ||
return | ||
} |
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 |
---|---|---|
@@ -1,22 +1,71 @@ | ||
// Package nodes provides nodes to use in codex AST's. | ||
package nodes | ||
|
||
import ( | ||
"github.com/chuckpreslar/codex/sql" | ||
) | ||
|
||
// ConstraintNode is a Nary node. | ||
// ConstraintNode is a specific Binary node. | ||
type ConstraintNode struct { | ||
Column interface{} | ||
Kind sql.Constraint | ||
Options []interface{} | ||
Column interface{} // Column the ConstraintNode affects. | ||
Options []interface{} // Options to apply to the ConstraintNode. | ||
} | ||
|
||
type NotNullNode ConstraintNode // NotNullNode is a ConstraintNode struct. | ||
type UniqueNode ConstraintNode // UniqueNode is a ConstraintNode struct. | ||
type PrimaryKeyNode ConstraintNode // PrimaryKeyNode is a ConstraintNode struct. | ||
type ForeignKeyNode ConstraintNode // ForeignKeyNode is a ConstraintNode struct. | ||
type CheckNode ConstraintNode // CheckNode is a ConstraintNode struct. | ||
type DefaultNode ConstraintNode // DefaultNode is a ConstraintNode struct. | ||
|
||
// ConstraintNode factory method. | ||
func Constraint(column interface{}, kind sql.Constraint, options ...interface{}) (constraint *ConstraintNode) { | ||
func Constraint(column interface{}, options ...interface{}) (constraint *ConstraintNode) { | ||
constraint = new(ConstraintNode) | ||
constraint.Column = column | ||
constraint.Kind = kind | ||
constraint.Options = options | ||
return | ||
} | ||
|
||
// NotNullNode factory method. | ||
func NotNull(column interface{}, options ...interface{}) (nnull *NotNullNode) { | ||
nnull = new(NotNullNode) | ||
nnull.Column = column | ||
nnull.Options = options | ||
return | ||
} | ||
|
||
// UniqueNode factory method. | ||
func Unique(column interface{}, options ...interface{}) (unique *UniqueNode) { | ||
unique = new(UniqueNode) | ||
unique.Column = column | ||
unique.Options = options | ||
return | ||
} | ||
|
||
// PrimaryKeyNode factory method. | ||
func PrimaryKey(column interface{}, options ...interface{}) (pkey *PrimaryKeyNode) { | ||
pkey = new(PrimaryKeyNode) | ||
pkey.Column = column | ||
pkey.Options = options | ||
return | ||
} | ||
|
||
// ForeignKeyNode factory method. | ||
func ForeignKey(column interface{}, options ...interface{}) (fkey *ForeignKeyNode) { | ||
fkey = new(ForeignKeyNode) | ||
fkey.Column = column | ||
fkey.Options = options | ||
return | ||
} | ||
|
||
// CheckNode factory method. | ||
func Check(column interface{}, options ...interface{}) (check *CheckNode) { | ||
check = new(CheckNode) | ||
check.Column = column | ||
check.Options = options | ||
return | ||
} | ||
|
||
// DefaultNode factory method. | ||
func Default(column interface{}, options ...interface{}) (def *DefaultNode) { | ||
def = new(DefaultNode) | ||
def.Column = column | ||
def.Options = options | ||
return | ||
} |
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,23 @@ | ||
package managers | ||
|
||
import ( | ||
"github.com/chuckpreslar/codex/managers" | ||
"github.com/chuckpreslar/codex/nodes" | ||
"github.com/chuckpreslar/codex/sql" | ||
"testing" | ||
) | ||
|
||
func TestAlterManager(t *testing.T) { | ||
relation := nodes.Relation("table") | ||
mgr := managers.Alteration(relation, true) | ||
|
||
// The following struct members should exist. | ||
_ = mgr.Tree | ||
|
||
// The following receiver methods should exist. | ||
_ = mgr.AddColumn(1, sql.STRING) | ||
_ = mgr.AddConstraint(1, sql.UNIQUE, 1, 2, 3) | ||
_ = mgr.SetEngine(1) | ||
_ = mgr.SetAdapter(1) | ||
_, _ = mgr.ToSql() | ||
} |
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
Oops, something went wrong.