Documentation ¶
Overview ¶
Example ¶
package main import ( "os" "github.com/schemalex/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` INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ); ALTER TABLE `hoge` ADD COLUMN `c` VARCHAR (20) NOT NULL DEFAULT "hoge"; SET FOREIGN_KEY_CHECKS = 1; COMMIT;
Index ¶
Examples ¶
Constants ¶
View Source
const Version = "v0.0.4"
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 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 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 BTREE CASCADE CHAR CHARACTER 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 FIRST FIXED FLOAT FOREIGN FULL FULLTEXT HASH IF INDEX INSERT_METHOD INT INTEGER KEY KEY_BLOCK_SIZE LAST 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 UNION UNIQUE UNSIGNED UPDATE USE USING VARBINARY VARCHAR YEAR ZEROFILL )
List of possible tokens
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
|
|
Click to show internal directories.
Click to hide internal directories.