MCPcopy Create free account
hub / github.com/AdRoll/baker / setupTable

Method setupTable

output/sqlite.go:306–332  ·  view source on GitHub ↗

setupTable either creates the table or, in case it already exists and the config has Clear=true, we truncate the table.

(tx *sql.Tx)

Source from the content-addressed store, hash-verified

304// setupTable either creates the table or, in case it already exists and the
305// config has Clear=true, we truncate the table.
306func (c *SQLite) setupTable(tx *sql.Tx) error {
307 // Build the SQL statement that creates the table.
308 // CREATE TABLE IF NOT EXISTS ? ( ?, ?, ... )
309 var fields []string
310 for _, f := range c.fieldNames {
311 fields = append(fields, sqliteQuote(f))
312 }
313 if c.isRaw {
314 // Raw record is a BLOB column.
315 fields = append(fields, sqliteQuote(c.cfg.RecordBlobName)+" BLOB")
316 }
317
318 sstmt := fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (%s)",
319 sqliteQuote(c.cfg.TableName), strings.Join(fields, ","))
320
321 stmt, err := tx.Prepare(sstmt)
322 if err != nil {
323 return fmt.Errorf("prepare create statement: %s", err)
324 }
325 if _, err = stmt.Exec(); err != nil {
326 stmt.Close()
327 return fmt.Errorf("create table: %s", err)
328 }
329 stmt.Close()
330
331 return c.maybeTruncate(tx)
332}
333
334func (c *SQLite) doRun(input <-chan baker.OutputRecord) error {
335 // Install a deferred rollback; if something errors out, we execute

Callers 1

doRunMethod · 0.95

Calls 3

maybeTruncateMethod · 0.95
sqliteQuoteFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected