Skip to content

Commit

Permalink
Add example_writer_test
Browse files Browse the repository at this point in the history
  • Loading branch information
rnixik committed Jul 20, 2018
1 parent 8628817 commit 27eec97
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions example_writer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

func Example_WriteRows() {
writer := &SimpleWriter{}
rows := make([]*map[string]interface{}, 0)
rows = append(rows, &map[string]interface{}{"name": "one", "title": "two"})
rows = append(rows, &map[string]interface{}{"id": int(123)})
rows = append(rows, &map[string]interface{}{"value": int(456)})
rows = append(rows, &map[string]interface{}{"amount": 1.23})
rows = append(rows, &map[string]interface{}{"chars": []uint8{0x26, 0x23, 0x29}})
rows = append(rows, &map[string]interface{}{"nulled": nil})
rows = append(rows, &map[string]interface{}{"strange": uintptr(1)})

writer.WriteRows("some_table", []string{}, rows)

// Output:
// some_table
// name = one;||title = two;||
// id = 123;||
// value = 456;||
// amount = 1.230000;||
// chars = &#);||
// nulled = NULL;||
// strange = UNDEFINED;||
}

func Example_WriteDDL() {
writer := &SimpleWriter{}
ddl := "CREATE TABLE `some_table` (\n"
ddl += " `id` bigint(20) NOT NULL,\n"
ddl += " `name` varchar(100) NOT NULL,\n"
ddl += " PRIMARY KEY (`id`),\n"
ddl += " UNIQUE INDEX `name` (`name`)\n"
ddl += ");"
writer.WriteDDL("some_table", ddl)

// Output:
// CREATE TABLE `some_table` (
// `id` bigint(20) NOT NULL,
// `name` varchar(100) NOT NULL,
// PRIMARY KEY (`id`),
// UNIQUE INDEX `name` (`name`)
// );
}
2 changes: 1 addition & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (w *SimpleWriter) WriteRows(tableName string, _ []string, rows []*map[strin
default:
value = "UNDEFINED"
}
fmt.Printf("%s = %s; ", field, value)
fmt.Printf("%s = %s;||", field, value)
}
fmt.Println("")
}
Expand Down

0 comments on commit 27eec97

Please sign in to comment.