Databases gives you simple asyncio support for a range of databases.
It allows you to make queries using the powerful SQLAlchemy Coreexpression language, and provides support for PostgreSQL, MySQL, and SQLite.
Databases is suitable for integrating against any async Web framework, such as Starlette,Sanic, Responder, Quart, aiohttp, Tornado, or FastAPI.
Documentation: https://www.encode.io/databases/
Requirements: Python 3.6+
$ pip install databases
You can install the required database drivers with:
$ pip install databases[postgresql]
$ pip install databases[mysql]
$ pip install databases[sqlite]
Driver support is provided using one of asyncpg, aiomysql, or aiosqlite.Note that if you are using any synchronous SQLAlchemy functions such as engine.create_all()
or alembic migrations then you still have to install a synchronous DB driver: psycopg2 for PostgreSQL and pymysql for MySQL.
For this example we'll create a very simple SQLite database to run somequeries against.
$ pip install databases[sqlite]
$ pip install ipython
We can now run a simple example from the console.
Note that we want to use ipython
here, because it supports using await
expressions directly from the console.
# Create a database instance, and connect to it.
from databases import Database
database = Database('sqlite:///example.db')
await database.connect()
# Create a table.
query = """CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)"""
await database.execute(query=query)
# Insert some data.
query = "INSERT INTO HighScores(name, score) VALUES (:name, :score)"
values = [
{"name": "Daisy", "score": 92},
{"name": "Neil", "score": 87},
{"name": "Carol", "score": 43},
]
await database.execute_many(query=query, values=values)
# Run a database query.
query = "SELECT * FROM HighScores"
rows = await database.fetch_all(query=query)
print('High Scores:', rows)
Check out the documentation on making database queriesfor examples of how to start using databases together with SQLAlchemy core expressions.
—
Databases is BSD licensed code. Designed & built in Brighton, England.
语法 查看数据库的语句是SHOW DATABASES,查看数据库语法格式是: SHOW DATABASES [LIKE '数据库名']; ;代表要执行以上语句 语法说明: LIKE是可选项,用于匹配特定的数据库名称,LIKE可以部分匹配,也可以完全匹配。这个LIKE 作用就是如果数据库庞大起来你指定搜索名字可以缩小搜索时间。 数据库名称是''包围的。 例子 创建并查看全部数据库 建一个名字叫t
mysqldump中–databases选项的作用 mysqldump --databases hellodb --single-transaction --trigger- E > /root/hello-$(date +%F) 这样加了--databases的语句 在备份的时候先是会创建表的,也就是说备份了整个hellodb的 如果不加--databses的话,表明只是备份hellodb中
Databases in Hive 1.如果在hive中未定义数据库的话,这个“default”作为默认的数据库。 2.创建数据库的语法很简单: hive> create databasefinancials; 如果financials存在的话,就会抛出错误,可以这样: hive> create databases IF NOT EXISTS financials; 3.在“database
SQL show databases 语句 SQL show databases 语句用于列出数据库系统中所有的数据库 show databases; 示例 使用show databases; SQL 语句来查看MySQL 数据库系统中所有的数据库。 mysql> show databases; +---------------------+ | Database | +-
吐槽:这个作业花了我挺长时间,究其原因是没有好好看 README.txt 的内容,不过浪费的时间还是足以让我学到些。 题目:Retrieving GEOData Download the code from http://www.py4e.com/code3/geodata.zip - then unzip the file and edit where.data to add an addres
FIT2094 Databases Normalisation and Logical Database Design - Clean Up Inc (CUI) FACULTY OF INFORMATION TECHNOLOGY Given the provided case study from assignment 1A, and additional forms/documents rela
介绍了人脸识别中常用的人脸库 AR Face Database Richard's MIT database CVL Database The Psychological Image Collection at Stirling Labeled Faces in the Wild The MUCT Face Database The Yale Face Database B The Yale Fa
"OPTIONS": {"init_command": "SET storage_engine=INNODB;"} 会报错,正确的解决非法为: "OPTIONS": {"init_command": "SET default_storage_engine=INNODB;"}
创建或进入数据库 use myDB 如果数据库不存在则创建数据库,如果数据库存在则进入数据库 查看数据库 show dbs 参考 https://docs.mongodb.com/manual/core/databases-and-collections/
更换数据库 migrate 下哈 admin 要重新建立 修改\mysite\settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } }