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) {
30
30
31
31
g .Snapshot ("ddl-string" , ddl .String ())
32
32
}
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 (
6
6
)
7
7
8
8
func ToMigrationStatements (path , ddl string ) ([]string , error ) {
9
- _ , err := parser .ParseString (path , ddl )
9
+ parsed , err := parser .ParseString (path , ddl )
10
10
if err != nil {
11
11
return nil , fmt .Errorf ("failed to parse DDL: %w" , err )
12
12
}
13
13
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
15
21
}
16
22
17
23
func (d * SpannerDDL ) String () string {
You can’t perform that action at this time.
0 commit comments