This is a short input on getting a table. This is something that would have helped me personally when starting to use the SQL module. I could be totally off base here since I'm new to GO, but it seems like the right thing to do.
diff --git a/SQLInterface.md b/SQLInterface.md
index 1561f11..bcdb708 100644
--- a/SQLInterface.md
+++ b/SQLInterface.md
@@ -141,4 +141,44 @@
```go
var name *string
err := db.QueryRowContext(ctx, "SELECT name FROM names WHERE id = $1", id).Scan(&name)
+```
+
+# Getting a table
+
+If you want an struct array from your SQL query.
+
+```go
+func getTable[T any](rows *sql.Rows) (out []T) {
+ var table []T
+ for rows.Next() {
+ var data T
+ s := reflect.ValueOf(&data).Elem()
+ numCols := s.NumField()
+ columns := make([]interface{}, numCols)
+
+ for i := 0; i < numCols; i++ {
+ field := s.Field(i)
+ columns[i] = field.Addr().Interface()
+ }
+
+ if err := rows.Scan(columns...); err != nil {
+ fmt.Println("Case Read Error ", err)
+ }
+
+ table = append(table, data)
+ }
+ return table
+}
+```
+
+Make sure to deal with nulls from the database.
+
+```go
+type User struct {
+ UUID sql.NullString
+ Name sql.NullString
+}
+
+rows, err := db.Query("SELECT * FROM Users")
+cases := getTable[User](rows)
```
\ No newline at end of file