SimpleMysql
An ultra simplistic wrapper for Python MySQLdb with very basic functionality
http://nadh.in/code/simplemysql
License: GPL v2
Installation
pip install simplemysql
Usage
from simplemysql import SimpleMysql
db = SimpleMysql(
host="localhost",
db="mydatabase",
user="username",
passwd="password"
)
# insert a record to the *books* table
db.insert("books", {"type": "paperback", "name": "Time Machine", "price": 5.55, year: "1997"})
book = db.getOne("books", ["name"], ["year = 1997"])
print "The book's name is " + book.name
Query methods
insert(), update(), delete(), getOne(), getAll(), query()
insert(table, record{})
Inserts a single record into a table.
db.insert("food", {"type": "fruit", "name": "Apple", "color": "red"})
db.insert("books", {"type": "paperback", "name": "Time Machine", "price": 5.55})
update(table, row{}, condition[])
Update one more or rows based on a condition (or no condition).
# update all rows
db.update("books", {"discount": 0})
# update rows based on a simple hardcoded condition
db.update("books",
{"discount": 10},
["id=1"]
)
# update rows based on a parametrized condition
db.update("books",
{"discount": 10},
("id=%s AND year=%s", [id, year])
)
insertOrUpdate(table, row{}, key)
Insert a new row, or update if there is a primary key conflict.
# insert a book with id 123. if it already exists, update values
db.insert("books",
{"id": 123, type": "paperback", "name": "Time Machine", "price": 5.55},
"id"
)
getOne(table, fields[], condition[], order[], limit[])
getAll(table, fields[], condition[], order[], limit[])
Get a single record or multiple records from a table given a condition (or no condition). The resultant rows are returned as namedtuples. getOne() returns a single namedtuple, and getAll() returns a list of namedtuples.
book = db.getOne("books", ["id", "name"])
# get a row based on a simple hardcoded condition
book = db.getOne("books", ["name", "year"], ("id=1"))
# get a row based on a simple hardcoded condition
book = db.getOne("books", ["name", "year"], ("id=1"))
# get multiple rows based on a parametrized condition
books = db.getAll("books",
["id", "name"],
("year > %s and price < 15", [year, 12.99])
)
# get multiple rows based on a parametrized condition with an order and limit specified
books = db.getAll("books",
["id", "name", "year"],
("year > %s and price < 15", [year, 12.99]),
["year", "DESC"], # ORDER BY year DESC
[0, 10] # LIMIT 0, 10
)
lastId()
Get the last insert id
delete(table, fields[], condition[], order[], limit[])
Delete one or more records based on a condition (or no condition)
# delete all rows
db.delete("books")
# delete rows based on a condition
db.delete("books", ("price > %s AND year < %s", [25, 1999]))
query(table)
Run a raw SQL query. The MySQLdb cursor is returned.
db.query("DELETE FROM books WHERE year > 2005")
Metadata
Release files for simplemysql 1.25
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| simplemysql-1.25.tar.gz | 4.5 kB | Without provenance | Details |
Release files / simplemysql-1.25.tar.gz
| Download URL | simplemysql-1.25.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd437c6bc7141f4bac40581725f42e7c645d79ec9ce6512227119506883de698
|
|
BLAKE2b-256 checksum How to use checksums |
9ad86c14e05a28ef89035a456c7f94ebe67a68fb13c1f2e3bc3bab6e81e0a9d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for simplemysql 1.25
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.