sqlread

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2018 License: MIT Imports: 7 Imported by: 0

README

sqlread

Go Report Card GoDoc Build Status

SQL Dump Parser - Currently a very fragile toy sql dump parser.

Currently very picky and only likes mysqldump generated output dumps. Compatability work in process.

Example usage

$ sqlread buildings.sql
2017/12/22 12:23:52 starting initial pass
2017/12/22 12:23:52 loaded from cache
2017/12/22 12:23:52 finished initial pass
SHOW TABLES;
buildings
2017/12/22 12:24:01 restarting lexer

SHOW COLUMNS FROM `buildings`;
building_id,int
account_id,int
title,varchar
descr,varchar
city,varchar
state_id,smallint
zip_code,varchar
deleted,tinyint
2017/12/22 12:24:08 restarting lexer

SELECT `building_id`, `title` FROM `buildings`;
2,Home Building
190,Test Building (demo)
192,Donat Building
194,Other Building
201,Sample Building (demo)
205,Johnson Building
2017/12/22 12:24:44 restarting lexer

SELECT `building_id`, `title` FROM `buildings` INTO OUTFILE "dump.csv";
2017/12/22 12:27:43 written to `dump.csv`
2017/12/22 12:27:43 restarting lexer

Documentation

Index

Constants

View Source
const (
	TIllegal lexItemType = iota

	TEof
	TSemi
	TComma

	TComment
	TDelim

	TNull
	TString
	TNumber
	TIdentifier

	TDropTableFullStmt
	TLockTableFullStmt
	TUnlockTablesFullStmt
	TSetFullStmt

	TLParen
	TRParen

	TCreateTable
	TCreateTableDetail
	TcreateTableExtraDetail

	TColumnType
	TColumnSize
	TColumnEnumVal
	TColumnDetails

	TInsertInto
	TInsertValues

	// Values Below Are Specific to the interpreter
	TIntpSelect
	TIntpStar
	TIntpFrom
	TIntpIntoOutfile

	TIntpShowTables
	TIntpShowColumns

	TIntpQuit
)

Variables

This section is empty.

Functions

func Lex

func Lex(input io.ReaderAt) (*lexer, chan LexItem)

func LexSection

func LexSection(input io.ReaderAt, off, n int64) (*lexer, chan LexItem)

func StartState

func StartState(l *lexer) state

Types

type InsertDetailParser

type InsertDetailParser struct {
	Out    chan []string
	ColInd []int
}

func NewInsertDetailParser

func NewInsertDetailParser() *InsertDetailParser

func (*InsertDetailParser) ParseStart

func (d *InsertDetailParser) ParseStart(p *Parser) parseState

type Intp

type Intp struct {
	EOF bool
}

func (*Intp) StartIntpState

func (intp *Intp) StartIntpState(l *lexer) state

type LexItem

type LexItem struct {
	Type lexItemType
	Val  string
	Pos  int64
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser is a state based SQL Parser that reads LexItems on a channel

func Parse

func Parse(l chan LexItem) *Parser

Parse creates a new parser

func (*Parser) Run

func (p *Parser) Run(start parseState) error

Run begins the Parser state machine It requires a start state

type Query

type Query struct {
	Columns []string
	Table   string
	Outfile *string
}

type QueryParser

type QueryParser struct {
	Tree QueryTree
}

func NewQueryParser

func NewQueryParser() *QueryParser

func (*QueryParser) ParseStart

func (q *QueryParser) ParseStart(p *Parser) parseState

type QueryTree

type QueryTree struct {
	Queries     []Query
	ShowTables  uint
	ShowColumns []string
	Quit        bool
}

type SummaryColumn

type SummaryColumn struct {
	Name string
	Type string
}

type SummaryDataLoc

type SummaryDataLoc struct {
	Start LexItem
	End   LexItem
}

type SummaryParser

type SummaryParser struct {
	Tree SummaryTree
}

func NewSummaryParser

func NewSummaryParser() *SummaryParser

func (*SummaryParser) ParseStart

func (t *SummaryParser) ParseStart(p *Parser) parseState

type SummaryTable

type SummaryTable struct {
	Create   LexItem
	Cols     []SummaryColumn
	DataLocs []SummaryDataLoc
}

type SummaryTree

type SummaryTree map[string]SummaryTable

Directories

Path Synopsis
cmd
sqlread command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL