JSON support.

This commit is contained in:
Nuno Cruces
2023-10-18 23:14:46 +01:00
parent 61da30f44a
commit d60fceac92
6 changed files with 134 additions and 5 deletions

View File

@@ -30,6 +30,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
"io"
"net/url"
@@ -272,6 +273,10 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
return newResult(c.Conn), nil
}
func (*conn) CheckNamedValue(arg *driver.NamedValue) error {
return nil
}
type stmt struct {
Stmt *sqlite3.Stmt
Conn *sqlite3.Conn
@@ -370,6 +375,8 @@ func (s *stmt) setupBindings(args []driver.NamedValue) error {
err = s.Stmt.BindZeroBlob(id, int64(a))
case time.Time:
err = s.Stmt.BindTime(id, a, sqlite3.TimeFormatDefault)
case json.Marshaler:
err = s.Stmt.BindJSON(id, a)
case nil:
err = s.Stmt.BindNull(id)
default:
@@ -386,7 +393,7 @@ func (s *stmt) setupBindings(args []driver.NamedValue) error {
func (s *stmt) CheckNamedValue(arg *driver.NamedValue) error {
switch arg.Value.(type) {
case bool, int, int64, float64, string, []byte,
sqlite3.ZeroBlob, time.Time, nil:
sqlite3.ZeroBlob, time.Time, json.Marshaler, nil:
return nil
default:
return driver.ErrSkip