|
|
|
# sql
|
|
|
|
|
|
|
|
*author: junjie.jiang*
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
## Desription
|
|
|
|
|
|
|
|
Read data from sqlite or mysql.
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
## Code Example
|
|
|
|
|
|
|
|
### Example
|
|
|
|
|
|
|
|
```python
|
|
|
|
from towhee import DataLoader, pipe, ops
|
|
|
|
p = (
|
|
|
|
pipe.input('image_path')
|
|
|
|
.map('image_path', 'image', ops.image_decode.cv2())
|
|
|
|
.map('image', 'vec', ops.image_embedding.timm(model_name='resnet50'))
|
|
|
|
.output('vec')
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
for data in DataLoader(ops.data_source.sql('sqlite:///./sqlite.db')):
|
|
|
|
print(p(data).to_list(kv_format=True))
|
|
|
|
|
|
|
|
# batch
|
|
|
|
for data in DataLoader(ops.data_source.sql('sqlite:///./sqlite.db'), batch_size=10):
|
|
|
|
p.batch(data)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Parameters:**
|
|
|
|
|
|
|
|
|
|
|
|
***sql_url:*** *str*
|
|
|
|
|
|
|
|
the url of the sql database for cache, such as '<db_type>+<db_driver>://<username>:<password>@<host>:<port>/<database>'
|
|
|
|
|
|
|
|
sqlite: sqlite:///./sqlite.db
|
|
|
|
|
|
|
|
mysql: mysql+pymysql://root:123456@127.0.0.1:3306/mysql
|
|
|
|
|
|
|
|
|
|
|
|
***table_name:*** *str*
|
|
|
|
|
|
|
|
table name
|
|
|
|
|
|
|
|
***cols:*** *str*
|
|
|
|
|
|
|
|
The columns to be queried, default to *, indicating all columns
|
|
|
|
|
|
|
|
If you want to query specific columns, use the column names and separate them with `,`, such as 'id,image_path,label'
|
|
|
|
|
|
|
|
|
|
|
|
***where:*** *str*
|
|
|
|
|
|
|
|
Where conditional statement, for example: id > 100
|
|
|
|
|
|
|
|
***limit:*** *int*
|
|
|
|
|
|
|
|
The default value is 500. If set to None, all data will be returned.
|
|
|
|
|