-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
94 lines (79 loc) · 2.27 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Package bactract is an exploration/attempt at extracting data from
// MS SQL Server bacpac files (BACpac-exTRACT)
package bactract
import (
"io/ioutil"
"os"
)
// To disable debug: toggle the following two lines and edit the SetDebug function
var debugFlag bool //= false // Whether or not to spew debugging information to STDOUT
//const debugFlag = false // Trim the length of byte arrays and strings when outputting debug information
const debugLen = 30 // Trim the length of byte arrays and strings when outputting debug information
// Note that this is an incomplete (I think) list of the possible
// datatypes, however, ya gotta work with what ya got
const (
NullDatatype = iota
BigInt = iota
Binary = iota
Bit = iota
Char = iota
Date = iota
Datetime = iota
DatetimeOffset = iota
Datetime2 = iota
Decimal = iota
Float = iota
Geography = iota
Int = iota
Money = iota
NChar = iota
NText = iota
Numeric = iota
NVarchar = iota
Real = iota
SmallDatetime = iota
SmallInt = iota
SmallMoney = iota
SQLVariant = iota
Time = iota
Text = iota
TinyInt = iota
UniqueIdentifier = iota
Varbinary = iota
Varchar = iota
)
// Bacpac is the base for an unzipped bacpac file
type Bacpac struct {
baseDir string
}
// New returns a new Bacpac
func New(baseDir string) (b Bacpac, err error) {
b.baseDir = baseDir
debugFlag = false
return b, err
}
func (b Bacpac) SetDebug(debug bool) {
debugFlag = debug
}
// ExportedTables returns the list of data containing tables found in the bacpac
func (b Bacpac) ExportedTables() (s []string, err error) {
// TODO: do we want to sort the list by size, largest tables first
// as this would benefit parallelizing the extraction process.
dir := catDir([]string{b.baseDir, "Data"})
dirs, err := ioutil.ReadDir(dir)
if err != nil {
return s, err
}
for _, d := range dirs {
p := catDir([]string{b.baseDir, "Data", d.Name()})
fi, err := os.Stat(p)
if err != nil {
return s, err
}
switch mode := fi.Mode(); {
case mode.IsDir():
s = append(s, d.Name())
}
}
return s, err
}