Skip to content

Commit

Permalink
Improve GQL schema statements
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb committed Sep 19, 2024
1 parent 394f285 commit 22b9d6d
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 408 deletions.
294 changes: 25 additions & 269 deletions ast/ast.go

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions ast/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,77 @@ func (e *ExecutePrivilegeOnTableFunction) End() token.Pos { return e.Names[len(e
func (r *RolePrivilege) Pos() token.Pos { return r.Role }
func (r *RolePrivilege) End() token.Pos { return r.Names[len(r.Names)-1].End() }

// ================================================================================
//
// GQL schema statements
//
// ================================================================================

func (c *CreatePropertyGraph) Pos() token.Pos { return c.Create }
func (c *CreatePropertyGraph) End() token.Pos { return c.Content.End() }

func (p *PropertyGraphContent) Pos() token.Pos { return p.Node }
func (p *PropertyGraphContent) End() token.Pos { return firstValidEnd(p.EdgeTables, p.NodeTables) }

func (p *PropertyGraphElementList) Pos() token.Pos { return p.LParen }
func (p *PropertyGraphElementList) End() token.Pos { return p.RParen + 1 }

func (p *PropertyGraphElement) Pos() token.Pos { return p.Name.Pos() }
func (p *PropertyGraphElement) End() token.Pos {
return firstValidEnd(p.Properties, p.Keys, p.Alias, p.Name)
}

func (p *PropertyGraphLabelAndPropertiesList) Pos() token.Pos { return firstPos(p.LabelAndProperties) }
func (p *PropertyGraphLabelAndPropertiesList) End() token.Pos { return lastEnd(p.LabelAndProperties) }

func (p *PropertyGraphLabelAndProperties) Pos() token.Pos { return p.Label.Pos() }
func (p *PropertyGraphLabelAndProperties) End() token.Pos {
return firstValidEnd(p.Properties, p.Label)
}

func (p *PropertyGraphElementLabelLabelName) Pos() token.Pos { return p.Label }
func (p *PropertyGraphElementLabelLabelName) End() token.Pos { return p.Name.End() }

func (p *PropertyGraphElementLabelDefaultLabel) Pos() token.Pos { return p.Default }
func (p *PropertyGraphElementLabelDefaultLabel) End() token.Pos { return p.Label + 5 }

func (p *PropertyGraphNodeElementKey) Pos() token.Pos { return p.PropertyGraphElementKey.Pos() }
func (p *PropertyGraphNodeElementKey) End() token.Pos { return p.PropertyGraphElementKey.End() }

func (p *PropertyGraphEdgeElementKeys) Pos() token.Pos { return p.Element.Pos() }
func (p *PropertyGraphEdgeElementKeys) End() token.Pos { return p.Destination.End() }

func (p *PropertyGraphElementKey) Pos() token.Pos { return p.Key }
func (p *PropertyGraphElementKey) End() token.Pos { return p.Keys.End() }

func (p *PropertyGraphSourceKey) Pos() token.Pos { return p.Source }
func (p *PropertyGraphSourceKey) End() token.Pos {
return firstValidEnd(p.ReferenceColumns, p.ElementReference)
}

func (p *PropertyGraphDestinationKey) Pos() token.Pos { return p.Destination }
func (p *PropertyGraphDestinationKey) End() token.Pos {
return firstValidEnd(p.ElementReference, p.ElementReference)
}

func (p *PropertyGraphColumnNameList) Pos() token.Pos { return p.LParen }
func (p *PropertyGraphColumnNameList) End() token.Pos { return p.RParen + 1 }

func (p *PropertyGraphNoProperties) Pos() token.Pos { return p.No }
func (p *PropertyGraphNoProperties) End() token.Pos { return p.Properties + 10 }

func (p *PropertyGraphPropertiesAre) Pos() token.Pos { return p.Properties }
func (p *PropertyGraphPropertiesAre) End() token.Pos { return p.ExceptColumns.End() }

func (p *PropertyGraphDerivedPropertyList) Pos() token.Pos { return p.Properties }
func (p *PropertyGraphDerivedPropertyList) End() token.Pos { return p.RParen + 1 }

func (p *PropertyGraphDerivedProperty) Pos() token.Pos { return p.Expr.Pos() }
func (p *PropertyGraphDerivedProperty) End() token.Pos { return firstValidEnd(p.PropertyName, p.Expr) }

func (g *DropPropertyGraph) Pos() token.Pos { return g.Drop }
func (g *DropPropertyGraph) End() token.Pos { return g.Name.End() }

// ================================================================================
//
// Types for Schema
Expand Down
95 changes: 95 additions & 0 deletions ast/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,101 @@ func (r *RolePrivilege) SQL() string {
return sql
}

// ================================================================================
//
// GQL schema statements
//
// ================================================================================

func (c *CreatePropertyGraph) SQL() string {
sql := "CREATE "
if c.OrReplace {
sql += "OR REPLACE "
}
sql += "PROPERTY GRAPH "
if c.IfNotExists {
sql += "IF NOT EXISTS "
}
sql += c.Name.SQL() + " " + c.Content.SQL()
return sql
}

func (p *PropertyGraphContent) SQL() string {
return "NODE TABLES" + p.NodeTables.SQL() + sqlOpt(" EDGE TABLES ", p.EdgeTables, "")
}

func (p *PropertyGraphElementList) SQL() string {
return "(" + sqlJoin(p.Elements, ", ") + ")"
}

func (p *PropertyGraphElement) SQL() string {
return p.Name.SQL() +
sqlOpt(" AS ", p.Alias, "") +
sqlOpt(" ", p.Keys, "") +
sqlOpt(" ", p.Properties, "")
}

func (p *PropertyGraphLabelAndPropertiesList) SQL() string {
return sqlJoin(p.LabelAndProperties, " ")
}

func (p *PropertyGraphLabelAndProperties) SQL() string {
return p.Label.SQL() + sqlOpt(" ", p.Properties, "")
}

func (p *PropertyGraphElementLabelLabelName) SQL() string { return "LABEL " + p.Name.SQL() }

func (p *PropertyGraphElementLabelDefaultLabel) SQL() string { return "DEFAULT LABEL" }

func (p *PropertyGraphNodeElementKey) SQL() string { return p.PropertyGraphElementKey.SQL() }

func (p *PropertyGraphElementKey) SQL() string {
return "KEY " + p.Keys.SQL()
}

func (p *PropertyGraphSourceKey) SQL() string {
return "SOURCE KEY " + p.Keys.SQL() +
" REFERENCES " + p.ElementReference.SQL() +
sqlOpt(" ", p.ReferenceColumns, "")
}

func (p *PropertyGraphDestinationKey) SQL() string {
return "DESTINATION KEY " + p.Keys.SQL() +
" REFERENCES " + p.ElementReference.SQL() +
sqlOpt(" ", p.ReferenceColumns, "")
}

func (p *PropertyGraphColumnNameList) SQL() string {
return "(" + sqlJoin(p.ColumnNameList, ", ") + ")"
}

func (*PropertyGraphNoProperties) isPropertyGraphElementProperties() {}

func (p *PropertyGraphNoProperties) SQL() string {
return "NO PROPERTIES"
}

func (p *PropertyGraphPropertiesAre) SQL() string {
return "PROPERTIES ARE ALL COLUMNS" + sqlOpt(" EXCEPT ", p.ExceptColumns, "")
}

func (p *PropertyGraphDerivedPropertyList) SQL() string {
return "PROPERTIES (" + sqlJoin(p.DerivedProperties, ", ") + ")"
}

func (p *PropertyGraphDerivedProperty) SQL() string {
return p.Expr.SQL() + sqlOpt(" AS ", p.PropertyName, "")
}

func (g *DropPropertyGraph) SQL() string {
sql := "DROP PROPERTY GRAPH "
if g.IfExists {
sql += "IF EXISTS "
}
sql += g.Name.SQL()
return sql
}

// ================================================================================
//
// Types for Schema
Expand Down
Loading

0 comments on commit 22b9d6d

Please sign in to comment.