websockets Documentation Release 9.0
asyncio import websockets async def hello(): uri = "ws://localhost:8765" async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") await websocket.recv() asyncio.get_event_loop() asyncio import websockets async def hello(): uri = "ws://localhost:8765" async with websockets.connect(uri) as websocket: name = input("What's your name? ") await websocket.send(name) print(f"> {name}") websocket.recv() print(f"< {greeting}") asyncio.get_event_loop().run_until_complete(hello()) Using connect() as an asynchronous context manager ensures the connection is closed before exiting the hello coroutine0 码力 | 81 页 | 352.88 KB | 1 年前3peewee Documentation Release 1.0.0
to explicitly connect to the database before using it, managing connections explicitly is a good practice. This way if the connection fails, the exception can be caught during the “connect” step, rather arbitrary time later when a query is executed. >>> database = SqliteDatabase('stats.db') >>> database.connect() To use this database with your models, specify it in an inner “Meta” class: class MyModel(Model): = peewee.CharField() ... ... class Meta: ... database = custom_db ... >>> custom_db.connect() >>> CustomModel.create_table() Best practice: define a base model class that points at the database0 码力 | 101 页 | 163.20 KB | 1 年前3peewee Documentation Release 1.0.0
to explicitly connect to the database before using it, managing connections explicitly is a good practice. This way if the connection fails, the exception can be caught during the “connect” step, rather arbitrary time later when a query is executed. >>> database = SqliteDatabase(’stats.db’) >>> database.connect() To use this database with your models, specify it in an inner “Meta” class: class MyModel(Model): whatev = peewee.CharField() ... ... class Meta: ... database = custom_db ... >>> custom_db.connect() >>> CustomModel.create_table() Best practice: define a base model class that points at the database0 码力 | 71 页 | 405.29 KB | 1 年前3peewee Documentation Release 2.10.2
database = db # this model uses the "people.db" database Now that we have our models, let’s connect to the database. Although it’s not necessary to open the connection explicitly, it is good practice connection when it receives a request, and close the connection when it sends the response. >>> db.connect() We’ll begin by creating the tables in the database that will store our data. This will create interpreter. We can create a small helper function to accomplish this: def create_tables(): database.connect() database.create_tables([User, Relationship, Message]) Open a python shell in the directory0 码力 | 275 页 | 276.96 KB | 1 年前3peewee Documentation Release 2.0.2
to explicitly connect to the database before using it, managing connections explicitly is a good practice. This way if the connection fails, the exception can be caught during the “connect” step, rather arbitrary time later when a query is executed. >>> database = SqliteDatabase(’stats.db’) >>> database.connect() To use this database with your models, specify it in an inner “Meta” class: class MyModel(Model): CustomModel(Model): ... whatev = CharField() ... ... class Meta: ... database = custom_db ... >>> custom_db.connect() >>> CustomModel.create_table() Best practice: define a base model class that points at the database0 码力 | 65 页 | 315.33 KB | 1 年前3peewee Documentation Release 2.10.2
Meta: database = db # this model uses the "people.db" database Now that we have our models, let’s connect to the database. Although it’s not necessary to open the connection explicitly, it is good practice connection when it receives a request, and close the connection when it sends the response. >>> db.connect() We’ll begin by creating the tables in the database that will store our data. This will create interpreter. We can create a small helper function to accomplish this: def create_tables(): database.connect() database.create_tables([User, Relationship, Message]) Open a python shell in the directory alongside0 码力 | 221 页 | 844.06 KB | 1 年前3peewee Documentation Release 3.0.0
database = db # this model uses the "people.db" database Now that we have our models, let’s connect to the database. Although it’s not necessary to open the connection explicitly, it is good practice connection when it receives a request, and close the connection when it sends the response. db.connect() We’ll begin by creating the tables in the database that will store our data. This will create instance, if you are using a connection pool, connections will only be recycled correctly if you call connect() and close(). We will tell flask that during the request/response cycle we need to create a connection0 码力 | 319 页 | 361.50 KB | 1 年前3websockets Documentation Release 5.0
/usr/bin/env python import asyncio import websockets async def hello(uri): async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") asyncio.get_event_loop().run_until_complete( # WS client example import asyncio import websockets async def hello(): async with websockets.connect( 'ws://localhost:8765') as websocket: name = input("What's your name? ") await websocket.send(name) websocket.recv() print(f"< {greeting}") asyncio.get_event_loop().run_until_complete(hello()) Using connect() as an asynchronous context manager ensures the connection is closed before exiting the hello coroutine0 码力 | 56 页 | 245.43 KB | 1 年前3peewee Documentation Release 3.5.0
database = db # this model uses the "people.db" database Now that we have our models, let’s connect to the database. Although it’s not necessary to open the connection explicitly, it is good practice connection when it receives a request, and close the connection when it sends the response. db.connect() We’ll begin by creating the tables in the database that will store our data. This will create instance, if you are using a connection pool, connections will only be recycled correctly if you call connect() and close(). We will tell flask that during the request/response cycle we need to create a connection0 码力 | 347 页 | 380.80 KB | 1 年前3peewee Documentation Release 3.4.0
database = db # this model uses the "people.db" database Now that we have our models, let’s connect to the database. Although it’s not necessary to open the connection explicitly, it is good practice connection when it receives a request, and close the connection when it sends the response. db.connect() We’ll begin by creating the tables in the database that will store our data. This will create instance, if you are using a connection pool, connections will only be recycled correctly if you call connect() and close(). We will tell flask that during the request/response cycle we need to create a connection0 码力 | 349 页 | 382.34 KB | 1 年前3
共 416 条
- 1
- 2
- 3
- 4
- 5
- 6
- 42