
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
gitlab.com/cosban/persistence
A dialect agnostic database driver extension to provide simplified query and transaction execution
Created for the sake of learning and memes
Open the connection to your database and specify which driver you will be using. Currently only postgres the postgres driver is written.
import (
_ "gitlab.com/cosban/persistence/postgres"
"gitlab.com/cosban/persistence"
)
func main() {
var connectionTemplate = "postgres://%s:%s@%s:%d/%s?sslmode=%s"
c, err := persistence.Open(
"postgres",
fmt.Sprintf(connectionTemplate, username, password, host, port, database, sslmode),
)
}
persistence can perform both raw, and built up queries.
// raw
var actualText string
query := persistence.Prepare("SELECT value FROM raw_example")
err := c.RawStatement().QueryRow(query, &actualText)
// builder
type Object struct {
Value string
}
var actual Object
err := c.BuildStatement().Query(&actual)
If a query is too complicated to easily build within the query builder, it is very simple to write and execute your own queries within a prepared statement.
// single row
var value1 string
var value2 string
statement := persistence.Prepare("SELECT value1, value2 FROM raw_example LIMIT 1")
err := c.RawStatement().QueryRow(query, &value1, &value2)
if err != nil {
panic(err)
}
fmt.Println(value1, value2)
// multiple rows
statement := persistence.Prepare("SELECT value1, value2 FROM raw_example LIMIT 1")
rows, err := c.RawStatement().Query(query)
if err != nil {
panic(err)
}
defer rows.Close()
for rows.Next() {
var value string
err = rows.Scan(&value)
if err != nil {
panic(err)
}
fmt.Println(value)
}
Either execute your transactions, i.e. your inserts, updates, deletes, Or your queries which return data.
For single statement operations, you may prepare and execute/query in one step using the PrepareAnd... methods available
from your connection. You can either query for a single row, or multiple. It's up to you.
// raw
statement := persistence.Prepare("INSERT INTO raw_example (value) VALUES ($1)", "beep boop")
err := persistence.RawStatement().ExecuteStatements(statement)
// builder
type Object struct {
Value string
}
actual := Object{"beep boop"}
err := c.BuildStatement().Insert(actual)
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.