File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed
.got/snapshots/TestToMigrationStatements Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 1+ [
2+ " CREATE TABLE test (id INT64)" ,
3+ " CREATE PROPERTY GRAPH SocialGraph NODE TABLES (Person) EDGE TABLES (Knows)"
4+ ]
Original file line number Diff line number Diff line change @@ -30,3 +30,19 @@ func TestBasic(t *testing.T) {
3030
3131 g .Snapshot ("ddl-string" , ddl .String ())
3232}
33+
34+ func TestToMigrationStatements (t * testing.T ) {
35+ g := got .T (t )
36+
37+ list , err := ToMigrationStatements ("" , `
38+ -- Comment
39+ CREATE TABLE test(id INT64);
40+
41+ CREATE PROPERTY GRAPH SocialGraph
42+ NODE TABLES (Person)
43+ EDGE TABLES (Knows);
44+ ` )
45+ g .E (err )
46+
47+ g .Snapshot ("list" , list )
48+ }
Original file line number Diff line number Diff line change @@ -6,12 +6,18 @@ import (
66)
77
88func ToMigrationStatements (path , ddl string ) ([]string , error ) {
9- _ , err := parser .ParseString (path , ddl )
9+ parsed , err := parser .ParseString (path , ddl )
1010 if err != nil {
1111 return nil , fmt .Errorf ("failed to parse DDL: %w" , err )
1212 }
1313
14- return nil , nil
14+ list := []string {}
15+
16+ for _ , statement := range parsed .Statements {
17+ list = append (list , strings .TrimRight (statement .String (), ";" ))
18+ }
19+
20+ return list , nil
1521}
1622
1723func (d * SpannerDDL ) String () string {
You can’t perform that action at this time.
0 commit comments