Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.