Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Formatter for CreateTable statement #12

Merged
merged 2 commits into from
Nov 20, 2018
Merged

Conversation

goccy
Copy link
Collaborator

@goccy goccy commented Nov 20, 2018

Add formatter for CreateTable statement, also add TableOption and ColumnOption structure for it.
But still not support PARTITION option.

DEMO

package main

import (
	"fmt"

	"github.com/knocknote/vitess-sqlparser/sqlparser"
)

func main() {
	stmt, err := sqlparser.Parse(`
CREATE TABLE partition_example (
  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  created_at datetime NOT NULL,
  PRIMARY KEY (id, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
PARTITION BY RANGE COLUMNS(created_at)
(PARTITION p201809 VALUES LESS THAN ('2018-10-01') ENGINE = InnoDB,
 PARTITION p201810 VALUES LESS THAN ('2018-11-01') ENGINE = InnoDB,
 PARTITION p201811 VALUES LESS THAN ('2018-12-01') ENGINE = InnoDB,
 PARTITION p201812 VALUES LESS THAN ('2019-01-01') ENGINE = InnoDB,
 PARTITION p201901 VALUES LESS THAN ('2019-02-01') ENGINE = InnoDB,
 PARTITION p201902 VALUES LESS THAN ('2019-03-01') ENGINE = InnoDB,
 PARTITION p201903 VALUES LESS THAN ('2019-04-01') ENGINE = InnoDB,
 PARTITION p201904 VALUES LESS THAN ('2019-05-01') ENGINE = InnoDB,
 PARTITION p201905 VALUES LESS THAN ('2019-06-01') ENGINE = InnoDB,
 PARTITION p201906 VALUES LESS THAN ('2019-07-01') ENGINE = InnoDB,
 PARTITION p201907 VALUES LESS THAN ('2019-08-01') ENGINE = InnoDB,
 PARTITION p201908 VALUES LESS THAN ('2019-09-01') ENGINE = InnoDB,
 PARTITION p201909 VALUES LESS THAN ('2019-10-01') ENGINE = InnoDB,
 PARTITION p201910 VALUES LESS THAN ('2019-11-01') ENGINE = InnoDB,
 PARTITION p201911 VALUES LESS THAN ('2019-12-01') ENGINE = InnoDB);
`)
	if err != nil {
		panic(err)
	}
	fmt.Println(sqlparser.String(stmt))
	/*
		       output the following

			   CREATE TABLE `partition_example` (
			           `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
			           `created_at` datetime NOT NULL,
			           PRIMARY KEY  (`id`, `created_at`)
			   ) ENGINE=InnoDB DEFAULT CHARSET=utf8
	*/
}

@ktsujichan
Copy link
Contributor

LGTM:+1:

@goccy
Copy link
Collaborator Author

goccy commented Nov 20, 2018

thanks!

@goccy goccy merged commit 877bed6 into develop Nov 20, 2018
@goccy goccy deleted the feature/add-formatter branch November 20, 2018 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants