goper

package module
v0.0.0-...-3796f20 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2013 License: MIT Imports: 8 Imported by: 0

README

goper

Utility for generating structs based off of database schemas. Intended to be used with something like sqlx.

Included:

  • support for mysql/sqlite (postgres pending)

Documentation

godoc

Installation

# install the library:
# install the sqlite development libraries
go get github.com/shanemhansen/goger

Examples

 #Add GOPATH/bin to your PATH
 go install github.com/shanemhansen/goper/...
 schema -driver sqlite3 -dsn path/to/file.sqlite3 > data.go
 schema -driver mysql -dsn "user:password@tcp(127.0.0.1:3306)/main" > data.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Done = errors.New("iteration done")

Session is deprecated in favor of sqlx

Functions

func CamelCase

func CamelCase(src string) string

A helper function that maps strings like product_variant to ProductVariant

func RegisterDialect

func RegisterDialect(driver string, dialect Dialect)

Types

type Column

type Column struct {
	Name   string
	DbType string
}

A column has a name and a database type (hackily converted to a gotype)

func (*Column) GoType

func (this *Column) GoType() string

Return the go type a database column should be mapped to. We always use pointers to handle null

type Dialect

type Dialect interface {
	CreateTable(table Table) string
	DropTable(table Table) string
	InsertOne(table Table) string
	ListTables(string) string
	ListColumns(string, Table) string
	Name() string
}

A Dialect is a set of functions for generating the SQL to obtain various metadata about a database.

func DialectByDriver

func DialectByDriver(driver string) Dialect

type MysqlDialect

type MysqlDialect int

func (MysqlDialect) CreateTable

func (this MysqlDialect) CreateTable(table Table) string

func (MysqlDialect) DropTable

func (this MysqlDialect) DropTable(table Table) string

func (MysqlDialect) InsertOne

func (this MysqlDialect) InsertOne(table Table) string

func (MysqlDialect) ListCollections

func (this MysqlDialect) ListCollections(dbname string, table Table) string

func (MysqlDialect) ListColumns

func (this MysqlDialect) ListColumns(dbname string, table Table) string

func (MysqlDialect) ListReferences

func (this MysqlDialect) ListReferences(dbname string, table Table) string

func (MysqlDialect) ListTables

func (this MysqlDialect) ListTables(dbname string) string

func (MysqlDialect) Name

func (this MysqlDialect) Name() string

type SchemaWriter

type SchemaWriter struct {
	PackageName string
	Outfile     io.Writer
	Tables      []*Table
}

A SchemaWriter writes a set of tables to the writer denoted by Outfile

func (*SchemaWriter) LoadSchema

func (this *SchemaWriter) LoadSchema(driver string, schema string, db *sql.DB) error

Load the database schema into memory using introspection, populating .Tables

func (*SchemaWriter) WriteField

func (this *SchemaWriter) WriteField(column *Column)

Write an individual field

func (*SchemaWriter) WriteSchema

func (this *SchemaWriter) WriteSchema()

Write the schema

func (*SchemaWriter) WriteType

func (this *SchemaWriter) WriteType(table *Table)

Write an individual table

type Session

type Session struct {
	DB *sql.DB
}

func (*Session) FromQuery

func (this *Session) FromQuery(query string, args ...interface{}) (gen StructGenerator, err error)

func (*Session) GetChildren

func (this *Session) GetChildren(obj interface{}, children string) error

type SqliteDialect

type SqliteDialect struct {
	MysqlDialect
}

func (SqliteDialect) ListColumns

func (this SqliteDialect) ListColumns(dbname string, table Table) string

func (SqliteDialect) ListTables

func (this SqliteDialect) ListTables(dbname string) string

func (SqliteDialect) Name

func (this SqliteDialect) Name() string

type StructGenerator

type StructGenerator func(interface{}) error

type Table

type Table struct {
	Name    string
	Columns []Column
}

A Table represents the metadata associated with a table (columns, datatypes, etc)

type TableStruct

type TableStruct interface {
	Table() string
}

Directories

Path Synopsis
schema -driver mysql|sqlite3 -dsn dsn Generate a set of a golang structs
schema -driver mysql|sqlite3 -dsn dsn Generate a set of a golang structs

Jump to

Keyboard shortcuts

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