Skip to content

Commit 52da535

Browse files
committed
Improve GQL schema statements
1 parent b818a86 commit 52da535

8 files changed

Lines changed: 326 additions & 408 deletions

ast/ast.go

Lines changed: 25 additions & 269 deletions
Large diffs are not rendered by default.

ast/pos.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,77 @@ func (e *ExecutePrivilegeOnTableFunction) End() token.Pos { return e.Names[len(e
796796
func (r *RolePrivilege) Pos() token.Pos { return r.Role }
797797
func (r *RolePrivilege) End() token.Pos { return r.Names[len(r.Names)-1].End() }
798798

799+
// ================================================================================
800+
//
801+
// GQL schema statements
802+
//
803+
// ================================================================================
804+
805+
func (c *CreatePropertyGraph) Pos() token.Pos { return c.Create }
806+
func (c *CreatePropertyGraph) End() token.Pos { return c.Content.End() }
807+
808+
func (p *PropertyGraphContent) Pos() token.Pos { return p.Node }
809+
func (p *PropertyGraphContent) End() token.Pos { return firstValidEnd(p.EdgeTables, p.NodeTables) }
810+
811+
func (p *PropertyGraphElementList) Pos() token.Pos { return p.LParen }
812+
func (p *PropertyGraphElementList) End() token.Pos { return p.RParen + 1 }
813+
814+
func (p *PropertyGraphElement) Pos() token.Pos { return p.Name.Pos() }
815+
func (p *PropertyGraphElement) End() token.Pos {
816+
return firstValidEnd(p.Properties, p.Keys, p.Alias, p.Name)
817+
}
818+
819+
func (p *PropertyGraphLabelAndPropertiesList) Pos() token.Pos { return firstPos(p.LabelAndProperties) }
820+
func (p *PropertyGraphLabelAndPropertiesList) End() token.Pos { return lastEnd(p.LabelAndProperties) }
821+
822+
func (p *PropertyGraphLabelAndProperties) Pos() token.Pos { return p.Label.Pos() }
823+
func (p *PropertyGraphLabelAndProperties) End() token.Pos {
824+
return firstValidEnd(p.Properties, p.Label)
825+
}
826+
827+
func (p *PropertyGraphElementLabelLabelName) Pos() token.Pos { return p.Label }
828+
func (p *PropertyGraphElementLabelLabelName) End() token.Pos { return p.Name.End() }
829+
830+
func (p *PropertyGraphElementLabelDefaultLabel) Pos() token.Pos { return p.Default }
831+
func (p *PropertyGraphElementLabelDefaultLabel) End() token.Pos { return p.Label + 5 }
832+
833+
func (p *PropertyGraphNodeElementKey) Pos() token.Pos { return p.PropertyGraphElementKey.Pos() }
834+
func (p *PropertyGraphNodeElementKey) End() token.Pos { return p.PropertyGraphElementKey.End() }
835+
836+
func (p *PropertyGraphEdgeElementKeys) Pos() token.Pos { return p.Element.Pos() }
837+
func (p *PropertyGraphEdgeElementKeys) End() token.Pos { return p.Destination.End() }
838+
839+
func (p *PropertyGraphElementKey) Pos() token.Pos { return p.Key }
840+
func (p *PropertyGraphElementKey) End() token.Pos { return p.Keys.End() }
841+
842+
func (p *PropertyGraphSourceKey) Pos() token.Pos { return p.Source }
843+
func (p *PropertyGraphSourceKey) End() token.Pos {
844+
return firstValidEnd(p.ReferenceColumns, p.ElementReference)
845+
}
846+
847+
func (p *PropertyGraphDestinationKey) Pos() token.Pos { return p.Destination }
848+
func (p *PropertyGraphDestinationKey) End() token.Pos {
849+
return firstValidEnd(p.ElementReference, p.ElementReference)
850+
}
851+
852+
func (p *PropertyGraphColumnNameList) Pos() token.Pos { return p.LParen }
853+
func (p *PropertyGraphColumnNameList) End() token.Pos { return p.RParen + 1 }
854+
855+
func (p *PropertyGraphNoProperties) Pos() token.Pos { return p.No }
856+
func (p *PropertyGraphNoProperties) End() token.Pos { return p.Properties + 10 }
857+
858+
func (p *PropertyGraphPropertiesAre) Pos() token.Pos { return p.Properties }
859+
func (p *PropertyGraphPropertiesAre) End() token.Pos { return p.ExceptColumns.End() }
860+
861+
func (p *PropertyGraphDerivedPropertyList) Pos() token.Pos { return p.Properties }
862+
func (p *PropertyGraphDerivedPropertyList) End() token.Pos { return p.RParen + 1 }
863+
864+
func (p *PropertyGraphDerivedProperty) Pos() token.Pos { return p.Expr.Pos() }
865+
func (p *PropertyGraphDerivedProperty) End() token.Pos { return firstValidEnd(p.PropertyName, p.Expr) }
866+
867+
func (g *DropPropertyGraph) Pos() token.Pos { return g.Drop }
868+
func (g *DropPropertyGraph) End() token.Pos { return g.Name.End() }
869+
799870
// ================================================================================
800871
//
801872
// Types for Schema

ast/sql.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,101 @@ func (r *RolePrivilege) SQL() string {
12461246
return sql
12471247
}
12481248

1249+
// ================================================================================
1250+
//
1251+
// GQL schema statements
1252+
//
1253+
// ================================================================================
1254+
1255+
func (c *CreatePropertyGraph) SQL() string {
1256+
sql := "CREATE "
1257+
if c.OrReplace {
1258+
sql += "OR REPLACE "
1259+
}
1260+
sql += "PROPERTY GRAPH "
1261+
if c.IfNotExists {
1262+
sql += "IF NOT EXISTS "
1263+
}
1264+
sql += c.Name.SQL() + " " + c.Content.SQL()
1265+
return sql
1266+
}
1267+
1268+
func (p *PropertyGraphContent) SQL() string {
1269+
return "NODE TABLES" + p.NodeTables.SQL() + sqlOpt(" EDGE TABLES ", p.EdgeTables, "")
1270+
}
1271+
1272+
func (p *PropertyGraphElementList) SQL() string {
1273+
return "(" + sqlJoin(p.Elements, ", ") + ")"
1274+
}
1275+
1276+
func (p *PropertyGraphElement) SQL() string {
1277+
return p.Name.SQL() +
1278+
sqlOpt(" AS ", p.Alias, "") +
1279+
sqlOpt(" ", p.Keys, "") +
1280+
sqlOpt(" ", p.Properties, "")
1281+
}
1282+
1283+
func (p *PropertyGraphLabelAndPropertiesList) SQL() string {
1284+
return sqlJoin(p.LabelAndProperties, " ")
1285+
}
1286+
1287+
func (p *PropertyGraphLabelAndProperties) SQL() string {
1288+
return p.Label.SQL() + sqlOpt(" ", p.Properties, "")
1289+
}
1290+
1291+
func (p *PropertyGraphElementLabelLabelName) SQL() string { return "LABEL " + p.Name.SQL() }
1292+
1293+
func (p *PropertyGraphElementLabelDefaultLabel) SQL() string { return "DEFAULT LABEL" }
1294+
1295+
func (p *PropertyGraphNodeElementKey) SQL() string { return p.PropertyGraphElementKey.SQL() }
1296+
1297+
func (p *PropertyGraphElementKey) SQL() string {
1298+
return "KEY " + p.Keys.SQL()
1299+
}
1300+
1301+
func (p *PropertyGraphSourceKey) SQL() string {
1302+
return "SOURCE KEY " + p.Keys.SQL() +
1303+
" REFERENCES " + p.ElementReference.SQL() +
1304+
sqlOpt(" ", p.ReferenceColumns, "")
1305+
}
1306+
1307+
func (p *PropertyGraphDestinationKey) SQL() string {
1308+
return "DESTINATION KEY " + p.Keys.SQL() +
1309+
" REFERENCES " + p.ElementReference.SQL() +
1310+
sqlOpt(" ", p.ReferenceColumns, "")
1311+
}
1312+
1313+
func (p *PropertyGraphColumnNameList) SQL() string {
1314+
return "(" + sqlJoin(p.ColumnNameList, ", ") + ")"
1315+
}
1316+
1317+
func (*PropertyGraphNoProperties) isPropertyGraphElementProperties() {}
1318+
1319+
func (p *PropertyGraphNoProperties) SQL() string {
1320+
return "NO PROPERTIES"
1321+
}
1322+
1323+
func (p *PropertyGraphPropertiesAre) SQL() string {
1324+
return "PROPERTIES ARE ALL COLUMNS" + sqlOpt(" EXCEPT ", p.ExceptColumns, "")
1325+
}
1326+
1327+
func (p *PropertyGraphDerivedPropertyList) SQL() string {
1328+
return "PROPERTIES (" + sqlJoin(p.DerivedProperties, ", ") + ")"
1329+
}
1330+
1331+
func (p *PropertyGraphDerivedProperty) SQL() string {
1332+
return p.Expr.SQL() + sqlOpt(" AS ", p.PropertyName, "")
1333+
}
1334+
1335+
func (g *DropPropertyGraph) SQL() string {
1336+
sql := "DROP PROPERTY GRAPH "
1337+
if g.IfExists {
1338+
sql += "IF EXISTS "
1339+
}
1340+
sql += g.Name.SQL()
1341+
return sql
1342+
}
1343+
12491344
// ================================================================================
12501345
//
12511346
// Types for Schema

0 commit comments

Comments
 (0)