Documentation ¶
Overview ¶
Example ¶
package main import ( "os" "github.com/jongsy/schemalex/diff" ) func main() { const sql1 = `CREATE TABLE hoge ( id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) );` const sql2 = `CREATE TABLE hoge ( id INTEGER NOT NULL AUTO_INCREMENT, c VARCHAR (20) NOT NULL DEFAULT "hoge", PRIMARY KEY (id) ); CREATE TABLE fuga ( id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) );` diff.Strings(os.Stdout, sql1, sql2, diff.WithTransaction(true)) }
Output: BEGIN; SET FOREIGN_KEY_CHECKS = 0; CREATE TABLE `fuga` ( `id` INT (11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ); ALTER TABLE `hoge` ADD COLUMN `c` VARCHAR (20) NOT NULL DEFAULT 'hoge' AFTER `id`; SET FOREIGN_KEY_CHECKS = 1; COMMIT;
Index ¶
Examples ¶
Constants ¶
const Version = "v0.1.1"
Version contains the version number. Note that this does not necessarily reflect the current state of the source code.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v0.0.9
type Option interface { Name() string Value() interface{} }
Option is a generic interface for objects that passes optional parameters to the various format functions in this package
type ParseError ¶
ParseError is returned from the various `Parse` methods when an invalid or unsupported SQL is found. When stringified, the result will look something like this:
parse error: expected RPAREN at line 3 column 14 "CREATE TABLE foo " <---- AROUND HERE
type Parser ¶
type Parser struct{}
Parser is responsible to parse a set of SQL statements
func (*Parser) Parse ¶
Parse parses the given set of SQL statements and creates a model.Stmts structure. If it encounters errors while parsing, the returned error will be a ParseError type.
type SchemaSource ¶ added in v0.0.7
type SchemaSource interface { // WriteSchema is responsible for doing whatever necessary to retrieve // the database schema and write to the given io.Writer WriteSchema(io.Writer) error }
SchemaSource is the interface used for objects that provide us with a MySQL database schema to work with.
func NewLocalFileSource ¶ added in v0.0.7
func NewLocalFileSource(s string) SchemaSource
NewLocalFileSource creates a SchemaSource whose contents are derived from the given local file
func NewLocalGitSource ¶ added in v0.0.7
func NewLocalGitSource(gitDir, file, commitish string) SchemaSource
NewLocalGitSource creates a SchemaSource whose contents are derived from the given file at the given commit ID in a git repository.
func NewMySQLSource ¶ added in v0.0.7
func NewMySQLSource(s string) SchemaSource
NewMySQLSource creates a SchemaSource whose contents are derived by accessing the specified MySQL instance.
MySQL sources respect extra parameters "ssl-ca", "ssl-cert", and "ssl-secret" (which all should point to local file names) when the "tls" parameter is set to some boolean true value. In this case, we register the given tls configuration using those values automatically.
Please note that the "tls" parameter MUST BE A BOOLEAN. Otherwise we expect that you have already registered your tls configuration manually, and that you gave us the name of that configuration
func NewReaderSource ¶ added in v0.0.7
func NewReaderSource(src io.Reader) SchemaSource
NewReaderSource creates a SchemaSource whose contents are read from the given io.Reader.
func NewSchemaSource ¶ added in v0.0.7
func NewSchemaSource(uri string) (SchemaSource, error)
NewSchemaSource creates a SchemaSource based on the given URI. Currently "-" (for stdin), "local-git://...", "mysql://...", and "file://..." are supported. A string that does not match any of the above patterns and has no scheme part is treated as a local file.
type TokenType ¶
type TokenType int
TokenType describes the possible types of tokens that schemalex understands
const ( ILLEGAL TokenType = iota EOF SPACE IDENT BACKTICK_IDENT DOUBLE_QUOTE_IDENT SINGLE_QUOTE_IDENT NUMBER LPAREN // ( RPAREN // ) COMMA // , SEMICOLON // ; DOT // . SLASH // / ASTERISK // * DASH // - PLUS // + SINGLE_QUOTE // ' DOUBLE_QUOTE // " EQUAL // = COMMENT_IDENT // // /* */, --, # ACTION AUTO_INCREMENT AVG_ROW_LENGTH BIGINT BINARY BIT BLOB BOOL BOOLEAN BTREE CASCADE CHAR CHARACTER CHARSET CHECK CHECKSUM COLLATE COMMENT COMPACT COMPRESSED CONNECTION CONSTRAINT CREATE CURRENT_TIMESTAMP DATA DATABASE DATE DATETIME DECIMAL DEFAULT DELAY_KEY_WRITE DELETE DIRECTORY DISK DOUBLE DROP DYNAMIC ENGINE ENUM EXISTS FALSE FIRST FIXED FLOAT FOREIGN FULL FULLTEXT HASH IF INDEX INSERT_METHOD INT INTEGER JSON KEY KEY_BLOCK_SIZE LAST LIKE LONGBLOB LONGTEXT MATCH MAX_ROWS MEDIUMBLOB MEDIUMINT MEDIUMTEXT MEMORY MIN_ROWS NO NOT NULL NUMERIC ON PACK_KEYS PARTIAL PASSWORD PRIMARY REAL REDUNDANT REFERENCES RESTRICT ROW_FORMAT SET SIMPLE SMALLINT SPATIAL STATS_AUTO_RECALC STATS_PERSISTENT STATS_SAMPLE_PAGES STORAGE TABLE TABLESPACE TEMPORARY TEXT TIME TIMESTAMP TINYBLOB TINYINT TINYTEXT TRUE UNION UNIQUE UNSIGNED UPDATE USE USING VARBINARY VARCHAR YEAR ZEROFILL ASC DESC NOW )
List of possible tokens
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package diff contains functions to generate SQL statements to migrate an old schema to the new schema
|
Package diff contains functions to generate SQL statements to migrate an old schema to the new schema |
internal
|
|