-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqimport.go
68 lines (51 loc) · 2.09 KB
/
sqimport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package sqlite
import (
"io"
"net/url"
)
///////////////////////////////////////////////////////////////////////////////
// TYPES
type SQImportConfig struct {
// Schema defines the table schema to import into. Optional.
Schema string `sqlite:"schema"`
// Name defines the table name to import into, if empty will be inferred
// from the import source URL
Name string `sqlite:"name"`
// Ext defines the extension to infer the mimetype from. Optional.
Ext string `sqlite:"ext"`
// Header when true indicates the first line of a CSV file is a header
Header bool `sqlite:"header"`
// TrimSpace when true indicates the CSV file should be trimmed of whitespace
// for each field
TrimSpace bool `sqlite:"trimspace"`
// Comment defines the character which indicates a line is a comment. Optional.
Comment rune `sqlite:"comment"`
// Delimiter defines the character which indicates a field delimiter. Optional.
Delimiter rune `sqlite:"delimiter"`
// LazyQuotes when true indicates the CSV file should allow non-standard quotes.
LazyQuotes bool `sqlite:"lazyquotes"`
// Overwrite existing table (will append data otherwise)
Overwrite bool `sqlite:"overwrite"`
}
///////////////////////////////////////////////////////////////////////////////
// INTERFACES
type SQImporter interface {
// ReadWrite will read from the source, and write to destination. This function
// should be called multiple times until io.EOF is returned, indicating that
// no more data is available.
ReadWrite(SQImportDecoder) error
// Return the URL of the source
URL() *url.URL
// Return the Table name for the destination
Name() string
// Return a decoder for a reader, mimetype or file extension (when starts with a .)
// Will return nil if no decoder is available. The mimetype can include
// the character set (e.g. text/csv; charset=utf-8)
Decoder(io.Reader, string) (SQImportDecoder, error)
}
type SQImportDecoder interface {
// Read from the source, return column names and values. May
// return nil values to skip a write. Returns io.EOF when no
// more data is available.
Read() ([]string, []interface{}, error)
}