sqlimporter

package module
v0.0.0-...-3e23f1e Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2018 License: MIT Imports: 16 Imported by: 0

README

SQL Importer

Import a CSV file into Postgres with automatic column typing and table creation.

Features:

  • Type inference for numbers, dates, datetimes, and booleans
  • Automatic table creation
  • Uniqueness and not null detection
  • Automatic decompressing of gzip and bzip2 files
  • Support for append instead of replace
  • Support for CSV files wider than 1600 columns (the Postgres limit)

Install

Download a pre-built release.

Or install it from source (requires Go).

go get github.com/chop-dbhi/sql-importer/cmd/sql-importer

Usage

Specify the database URL and a CSV file to import. The table name will be derived from the filename by default.

sql-importer -db postgres://127.0.0.1:5432/postgres data.csv

See other options by running sql-importer -h.

Status

Beta, works as expected. Command line options will likely change.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Import

func Import(r *Request) error

Types

type Client

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

func New

func New(db *sql.DB) *Client

func (*Client) Append

func (c *Client) Append(schemaName, tableName string, tableSchema *Schema, cr *csv.Reader) (int64, error)

func (*Client) Replace

func (c *Client) Replace(schemaName, tableName string, tableSchema *Schema, cr *csv.Reader) (int64, error)

type Field

type Field struct {
	Name     string
	Type     string
	Multiple bool
	Unique   bool
	Nullable bool
}

Field is a data definition on a schema.

type Request

type Request struct {
	// Input path.
	Path string

	// Target database.
	Database string
	Schema   string
	Table    string

	// Behavior
	AppendTable bool
	CStore      bool

	// File specifics.
	CSV         bool
	Compression string

	// CSV
	Delimiter string
	Header    bool
}

type Schema

type Schema struct {
	Cstore bool
	Fields []*Field
}

func NewSchema

func NewSchema(p *profile.Profile) *Schema

Directories

Path Synopsis
cmd
csv

Jump to

Keyboard shortcuts

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