mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
Go 1.23.
This commit is contained in:
15
conn.go
15
conn.go
@@ -3,6 +3,7 @@ package sqlite3
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"iter"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -503,10 +504,16 @@ func (c *Conn) error(rc res_t, sql ...string) error {
|
|||||||
return c.sqlite.error(rc, c.handle, sql...)
|
return c.sqlite.error(rc, c.handle, sql...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) stmtsIter(yield func(*Stmt) bool) {
|
// Stmts returns an iterator for the prepared statements
|
||||||
for _, s := range c.stmts {
|
// associated with the database connection.
|
||||||
if !yield(s) {
|
//
|
||||||
break
|
// https://sqlite.org/c3ref/next_stmt.html
|
||||||
|
func (c *Conn) Stmts() iter.Seq[*Stmt] {
|
||||||
|
return func(yield func(*Stmt) bool) {
|
||||||
|
for _, s := range c.stmts {
|
||||||
|
if !yield(s) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
conn_iter.go
11
conn_iter.go
@@ -1,11 +0,0 @@
|
|||||||
//go:build go1.23
|
|
||||||
|
|
||||||
package sqlite3
|
|
||||||
|
|
||||||
import "iter"
|
|
||||||
|
|
||||||
// Stmts returns an iterator for the prepared statements
|
|
||||||
// associated with the database connection.
|
|
||||||
//
|
|
||||||
// https://sqlite.org/c3ref/next_stmt.html
|
|
||||||
func (c *Conn) Stmts() iter.Seq[*Stmt] { return c.stmtsIter }
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
//go:build !go1.23
|
|
||||||
|
|
||||||
package sqlite3
|
|
||||||
|
|
||||||
// Stmts returns an iterator for the prepared statements
|
|
||||||
// associated with the database connection.
|
|
||||||
//
|
|
||||||
// https://sqlite.org/c3ref/next_stmt.html
|
|
||||||
func (c *Conn) Stmts() func(func(*Stmt) bool) { return c.stmtsIter }
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
module github.com/ncruces/go-sqlite3/embed/bcw2
|
module github.com/ncruces/go-sqlite3/embed/bcw2
|
||||||
|
|
||||||
go 1.22.0
|
go 1.23.0
|
||||||
|
|
||||||
toolchain go1.24.0
|
toolchain go1.24.0
|
||||||
|
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
//go:build !go1.23
|
|
||||||
|
|
||||||
package fileio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/ncruces/go-sqlite3/internal/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Adapted from: https://research.swtch.com/coro
|
|
||||||
|
|
||||||
const errCoroCanceled = util.ErrorString("coroutine canceled")
|
|
||||||
|
|
||||||
func coroNew[In, Out any](f func(In, func(Out) In) Out) (resume func(In) (Out, bool), cancel func()) {
|
|
||||||
type msg[T any] struct {
|
|
||||||
panic any
|
|
||||||
val T
|
|
||||||
}
|
|
||||||
|
|
||||||
cin := make(chan msg[In])
|
|
||||||
cout := make(chan msg[Out])
|
|
||||||
running := true
|
|
||||||
resume = func(in In) (out Out, ok bool) {
|
|
||||||
if !running {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cin <- msg[In]{val: in}
|
|
||||||
m := <-cout
|
|
||||||
if m.panic != nil {
|
|
||||||
panic(m.panic)
|
|
||||||
}
|
|
||||||
return m.val, running
|
|
||||||
}
|
|
||||||
cancel = func() {
|
|
||||||
if !running {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
e := fmt.Errorf("%w", errCoroCanceled)
|
|
||||||
cin <- msg[In]{panic: e}
|
|
||||||
m := <-cout
|
|
||||||
if m.panic != nil && m.panic != e {
|
|
||||||
panic(m.panic)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
yield := func(out Out) In {
|
|
||||||
cout <- msg[Out]{val: out}
|
|
||||||
m := <-cin
|
|
||||||
if m.panic != nil {
|
|
||||||
panic(m.panic)
|
|
||||||
}
|
|
||||||
return m.val
|
|
||||||
}
|
|
||||||
go func() {
|
|
||||||
defer func() {
|
|
||||||
if running {
|
|
||||||
running = false
|
|
||||||
cout <- msg[Out]{panic: recover()}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
var out Out
|
|
||||||
m := <-cin
|
|
||||||
if m.panic == nil {
|
|
||||||
out = f(m.val, yield)
|
|
||||||
}
|
|
||||||
running = false
|
|
||||||
cout <- msg[Out]{val: out}
|
|
||||||
}()
|
|
||||||
return resume, cancel
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ package fileio
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"iter"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -63,7 +64,7 @@ func (d fsdir) Open() (sqlite3.VTabCursor, error) {
|
|||||||
type cursor struct {
|
type cursor struct {
|
||||||
fsdir
|
fsdir
|
||||||
base string
|
base string
|
||||||
resume resume
|
resume func() (entry, bool)
|
||||||
cancel func()
|
cancel func()
|
||||||
curr entry
|
curr entry
|
||||||
eof bool
|
eof bool
|
||||||
@@ -101,14 +102,26 @@ func (c *cursor) Filter(idxNum int, idxStr string, arg ...sqlite3.Value) error {
|
|||||||
c.base = base
|
c.base = base
|
||||||
}
|
}
|
||||||
|
|
||||||
c.resume, c.cancel = pull(c, root)
|
c.resume, c.cancel = iter.Pull(func(yield func(entry) bool) {
|
||||||
|
walkDir := func(path string, d fs.DirEntry, err error) error {
|
||||||
|
if yield(entry{d, err, path}) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fs.SkipAll
|
||||||
|
}
|
||||||
|
if c.fsys != nil {
|
||||||
|
fs.WalkDir(c.fsys, root, walkDir)
|
||||||
|
} else {
|
||||||
|
filepath.WalkDir(root, walkDir)
|
||||||
|
}
|
||||||
|
})
|
||||||
c.eof = false
|
c.eof = false
|
||||||
c.rowID = 0
|
c.rowID = 0
|
||||||
return c.Next()
|
return c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cursor) Next() error {
|
func (c *cursor) Next() error {
|
||||||
curr, ok := next(c)
|
curr, ok := c.resume()
|
||||||
c.curr = curr
|
c.curr = curr
|
||||||
c.eof = !ok
|
c.eof = !ok
|
||||||
c.rowID++
|
c.rowID++
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
//go:build !go1.23
|
|
||||||
|
|
||||||
package fileio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
type resume = func(struct{}) (entry, bool)
|
|
||||||
|
|
||||||
func next(c *cursor) (entry, bool) {
|
|
||||||
return c.resume(struct{}{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func pull(c *cursor, root string) (resume, func()) {
|
|
||||||
return coroNew(func(_ struct{}, yield func(entry) struct{}) entry {
|
|
||||||
walkDir := func(path string, d fs.DirEntry, err error) error {
|
|
||||||
yield(entry{d, err, path})
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if c.fsys != nil {
|
|
||||||
fs.WalkDir(c.fsys, root, walkDir)
|
|
||||||
} else {
|
|
||||||
filepath.WalkDir(root, walkDir)
|
|
||||||
}
|
|
||||||
return entry{}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
//go:build go1.23
|
|
||||||
|
|
||||||
package fileio
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
"iter"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
type resume = func() (entry, bool)
|
|
||||||
|
|
||||||
func next(c *cursor) (entry, bool) {
|
|
||||||
return c.resume()
|
|
||||||
}
|
|
||||||
|
|
||||||
func pull(c *cursor, root string) (resume, func()) {
|
|
||||||
return iter.Pull(func(yield func(entry) bool) {
|
|
||||||
walkDir := func(path string, d fs.DirEntry, err error) error {
|
|
||||||
if yield(entry{d, err, path}) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return fs.SkipAll
|
|
||||||
}
|
|
||||||
if c.fsys != nil {
|
|
||||||
fs.WalkDir(c.fsys, root, walkDir)
|
|
||||||
} else {
|
|
||||||
filepath.WalkDir(root, walkDir)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/ncruces/go-sqlite3
|
module github.com/ncruces/go-sqlite3
|
||||||
|
|
||||||
go 1.22.0
|
go 1.23.0
|
||||||
|
|
||||||
toolchain go1.24.0
|
toolchain go1.24.0
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module github.com/ncruces/go-sqlite3/gormlite
|
module github.com/ncruces/go-sqlite3/gormlite
|
||||||
|
|
||||||
go 1.22.0
|
go 1.23.0
|
||||||
|
|
||||||
toolchain go1.24.0
|
toolchain go1.24.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user