Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[interest check for new store] sqlite3 store using CGO-less modernc.org/sqlite #214

Open
rmmh opened this issue Jun 8, 2024 · 0 comments

Comments

@rmmh
Copy link

rmmh commented Jun 8, 2024

Is there interest in an sqlite3 store using the CGO-less translation of sqlite3 at https://modernc.org/sqlite + https://github.com/zombiezen/go-sqlite ? Performance is roughly 30% worse than the CGO version.

The translation from sqlite3store is relatively trivial, here's a snippet:

func (p *SQLite3XStore) exec(query string, opts *sqlitex.ExecOptions) error {
	conn, err := p.pool.Take(context.Background())
	if err != nil {
		return err
	}
	defer p.pool.Put(conn)
	return sqlitex.Execute(conn, query, opts)
}

// Find returns the data for a given session token from the SQLite3XStore instance.
// If the session token is not found or is expired, the returned exists flag will
// be set to false.
func (p *SQLite3XStore) Find(token string) (b []byte, exists bool, err error) {
	err = p.exec("SELECT data FROM sessions WHERE token = $1 AND julianday('now') < expiry",
		&sqlitex.ExecOptions{
			Args: []any{token},
			ResultFunc: func(stmt *sqlite.Stmt) error {
				exists = true
				b = make([]byte, stmt.ColumnLen(0))
				stmt.ColumnBytes(0, b)
				return nil
			},
		})
	return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant