| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Table of Contents
This package contains a pure-Python CovenantSQL client library, based on PEP 249.
NOTE: PyCovenantSQL only support high level APIs defined in PEP 249.
Package is uploaded on PyPI.
You can install it with pip:
$ python3 -m pip install PyCovenantSQL
Documentation is available online: https://PyCovenantSQL.readthedocs.io/
Key file and database_id can get from: https://testnet.covenantsql.io/quickstart
For support, please refer to the StackOverflow.
The following examples make use of a simple table
CREATE TABLE `users` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`email` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL
);import pycovenantsql.cursors
# user key file location
key = '/path/to/private.key'
# Connect to the database
connection = pycovenantsql.connect(host='localhost',
port=11108,
key=key,
database='database_id'
)
try:
with connection.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('webmaster@python.org', 'very-secret'))
# connection is autocommit. No need to commit in any case.
# connection.commit()
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('webmaster@python.org',))
result = cursor.fetchone()
print(result)
finally:
connection.close()This example will print:
{'password': 'very-secret', 'id': 1}PyCovenantSQL is released under the Apache 2.0 License. See LICENSE for more information.
| Back | FazBrowse Home | New Git URL |