feat: 新增技能扩展N9一章相关示例源码
This commit is contained in:
21
code/newsletter/N9/pw_connect.py
Normal file
21
code/newsletter/N9/pw_connect.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import pathlib
|
||||
|
||||
import peewee as pw
|
||||
|
||||
db_url = pathlib.Path(__file__).parent.joinpath("./mydb.sqlite3")
|
||||
db = pw.SqliteDatabase(db_url)
|
||||
|
||||
|
||||
# # equivalent to this:
|
||||
# db_url = pathlib.Path(__file__).parent.joinpath("./mydb.sqlite3")
|
||||
# db = pw.SqliteDatabase(None)
|
||||
# db.init(db_url)
|
||||
|
||||
|
||||
db.connect()
|
||||
|
||||
stmt = db.execute_sql("SELECT 1 as foo;").fetchall()
|
||||
print(stmt)
|
||||
|
||||
|
||||
db.close()
|
||||
Reference in New Issue
Block a user