Skip to content

a SQL parser to parse table schema dumped from mysql database

Notifications You must be signed in to change notification settings

meican-dev/sqlparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlparser

A Golang library to parse table schema dumped from MySQL database.

Usage:

  1. Dump table structure from mysql database
mysqldump -d -hlocalhost -uroot -p mydb > table_schema.sql
  1. Parse table schema in go program
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/meican-dev/sqlparser"
)

func main() {
	schemaFile := "table_schema.sql"
	file, err := os.Open(schemaFile)
	if err != nil {
		log.Fatalln(err)
	}
	parser := sqlparser.NewParser(file)
	schema, err := parser.Parse()
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("table schema: %v\n", schema)
}

Warning: This library is primarily used to parse dumped table schema which is well-formed SQL statement. It's not robust to parse any SQL statement

About

a SQL parser to parse table schema dumped from mysql database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages