| 8 | ) |
| 9 | |
| 10 | func TestCreateSequenceStatement_ToSQL(t *testing.T) { |
| 11 | tests := []struct { |
| 12 | name string |
| 13 | stmt *ast.CreateSequenceStatement |
| 14 | want string |
| 15 | }{ |
| 16 | { |
| 17 | name: "minimal", |
| 18 | stmt: &ast.CreateSequenceStatement{ |
| 19 | Name: &ast.Identifier{Name: "seq_orders"}, |
| 20 | }, |
| 21 | want: "CREATE SEQUENCE seq_orders", |
| 22 | }, |
| 23 | { |
| 24 | name: "or replace", |
| 25 | stmt: &ast.CreateSequenceStatement{ |
| 26 | Name: &ast.Identifier{Name: "seq_orders"}, |
| 27 | OrReplace: true, |
| 28 | }, |
| 29 | want: "CREATE OR REPLACE SEQUENCE seq_orders", |
| 30 | }, |
| 31 | { |
| 32 | name: "if not exists", |
| 33 | stmt: &ast.CreateSequenceStatement{ |
| 34 | Name: &ast.Identifier{Name: "seq_orders"}, |
| 35 | IfNotExists: true, |
| 36 | }, |
| 37 | want: "CREATE SEQUENCE IF NOT EXISTS seq_orders", |
| 38 | }, |
| 39 | { |
| 40 | name: "with options", |
| 41 | stmt: &ast.CreateSequenceStatement{ |
| 42 | Name: &ast.Identifier{Name: "s"}, |
| 43 | Options: ast.SequenceOptions{ |
| 44 | StartWith: &ast.LiteralValue{Value: "1"}, |
| 45 | IncrementBy: &ast.LiteralValue{Value: "1"}, |
| 46 | MinValue: &ast.LiteralValue{Value: "1"}, |
| 47 | MaxValue: &ast.LiteralValue{Value: "9999"}, |
| 48 | Cache: &ast.LiteralValue{Value: "100"}, |
| 49 | CycleMode: ast.CycleBehavior, |
| 50 | }, |
| 51 | }, |
| 52 | want: "CREATE SEQUENCE s START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 9999 CACHE 100 CYCLE", |
| 53 | }, |
| 54 | { |
| 55 | name: "nocycle", |
| 56 | stmt: &ast.CreateSequenceStatement{ |
| 57 | Name: &ast.Identifier{Name: "s"}, |
| 58 | Options: ast.SequenceOptions{CycleMode: ast.NoCycleBehavior}, |
| 59 | }, |
| 60 | want: "CREATE SEQUENCE s NOCYCLE", |
| 61 | }, |
| 62 | { |
| 63 | name: "nocache", |
| 64 | stmt: &ast.CreateSequenceStatement{ |
| 65 | Name: &ast.Identifier{Name: "s"}, |
| 66 | Options: ast.SequenceOptions{NoCache: true}, |
| 67 | }, |