aboutsummaryrefslogtreecommitdiff
path: root/lib/sql/row.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-02-13 20:14:39 +0700
committerShulhan <m.shulhan@gmail.com>2020-02-13 20:29:20 +0700
commit2425c08bc372809c28bea021cd9ed0de3b8eebb2 (patch)
tree637c3e2963e870ad55afc51aae23e7d013b62483 /lib/sql/row.go
parent59a272ea3a32d19f35cffec31b36d7462039768e (diff)
downloadpakakeh.go-2425c08bc372809c28bea021cd9ed0de3b8eebb2.tar.xz
sql: a new package as an extension to "database/sql"
Diffstat (limited to 'lib/sql/row.go')
-rw-r--r--lib/sql/row.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/sql/row.go b/lib/sql/row.go
new file mode 100644
index 00000000..524c540f
--- /dev/null
+++ b/lib/sql/row.go
@@ -0,0 +1,34 @@
+// Copyright 2020, Shulhan <m.shulhan@gmail.com>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package sql
+
+//
+// Row represent a single row in table.
+//
+type Row map[string]interface{}
+
+//
+// ExtractSQLFields extract the column's name, column place holder (default is
+// "?"), and column values; as slices.
+//
+func (row Row) ExtractSQLFields() (
+ names, holders []string, values []interface{},
+) {
+ if len(row) == 0 {
+ return nil, nil, nil
+ }
+
+ names = make([]string, 0, len(row))
+ holders = make([]string, 0, len(row))
+ values = make([]interface{}, 0, len(row))
+
+ for k, v := range row {
+ names = append(names, k)
+ holders = append(holders, "?")
+ values = append(values, v)
+ }
+
+ return names, holders, values
+}