2023-01-03 21:45:35 +09:00
|
|
|
package d1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql/driver"
|
|
|
|
"errors"
|
2023-02-26 12:07:38 +09:00
|
|
|
"syscall/js"
|
2023-01-03 21:45:35 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
type Conn struct {
|
2023-02-26 12:07:38 +09:00
|
|
|
dbObj js.Value
|
2023-01-03 21:45:35 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ driver.Conn = (*Conn)(nil)
|
|
|
|
_ driver.ConnBeginTx = (*Conn)(nil)
|
|
|
|
_ driver.ConnPrepareContext = (*Conn)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Conn) Prepare(query string) (driver.Stmt, error) {
|
2023-02-26 12:07:38 +09:00
|
|
|
stmtObj := c.dbObj.Call("prepare", query)
|
2023-02-12 01:50:45 +09:00
|
|
|
return &stmt{
|
|
|
|
stmtObj: stmtObj,
|
|
|
|
}, nil
|
2023-01-03 21:45:35 +09:00
|
|
|
}
|
|
|
|
|
2023-02-26 12:07:38 +09:00
|
|
|
func (c *Conn) PrepareContext(_ context.Context, query string) (driver.Stmt, error) {
|
|
|
|
return c.Prepare(query)
|
|
|
|
}
|
|
|
|
|
2023-01-03 21:45:35 +09:00
|
|
|
func (c *Conn) Close() error {
|
|
|
|
// do nothing
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conn) Begin() (driver.Tx, error) {
|
2023-01-09 23:10:30 +09:00
|
|
|
return nil, errors.New("d1: Begin is deprecated and not implemented")
|
2023-01-03 21:45:35 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Conn) BeginTx(context.Context, driver.TxOptions) (driver.Tx, error) {
|
|
|
|
return nil, errors.New("d1: transaction is not currently supported")
|
|
|
|
}
|