pySDBAPI - simple database API. Use a couple of lines to make a request
- Use a single decorator to complete a request. Receive OrderedDict immediately in response.
- If you need to display the table in the console, then use the show_table parameter
- So far only SQLite is supported, support for other databases (MySQL, PostgreSQL and others) will be added in the future
poetry add pysdbapi
or
pip install pysdbapi
This dependency is needed to print the table to the console
poetry add pysdbapi[pretty]
This code sends a message on your behalf to the chat
import pysdbapi
DATABASE_SETTINGS = {"database": "test.db"}
db = pysdbapi.DBApi(DATABASE_SETTINGS)
@db.execute_sql()
def get_all_posts():
return """SELECT * FROM posts"""
@db.execute_sql(show_table=True)
def get_all_posts__table():
return """SELECT * FROM posts"""
Result:
# Example show table
+----+-----------+----------------------+
| id | title | text |
+----+-----------+----------------------+
| 1 | Article 1 | Some text in article |
| 2 | Article 2 | Some text in article |
| 3 | Article 3 | Some text in article |
| 4 | Article 4 | Some text in article |
| 5 | Article 5 | Some text in article |
| 6 | dasdas | sddsdas |
+----+-----------+----------------------+