insert
sc_crawler.insert
#
can_bulk_insert
#
Checks if bulk insert is supported for the engine dialect of a SQLModel session.
validate_items
#
Validates a list of items against a pydantic.BaseModel definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
BaseModel
|
An SQLModel model to be used for validation. |
required |
items |
List[dict]
|
List of dictionaries to be checked against |
required |
vendor |
Optional[Vendor]
|
Optional Vendor instance used for logging and progress bar updates. |
None
|
prefix |
str
|
Optional extra description for the model added in front of the model name in logs and progress bar updates. |
''
|
Returns:
Type | Description |
---|---|
List[dict]
|
List of validated dicts in the same order. Note that missing fields has been filled in with default values (needed for bulk inserts). |
Source code in sc_crawler/insert.py
bulk_insert_items
#
Bulk inserts items into a SQLModel table with ON CONFLICT
update.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
SQLModel
|
An SQLModel table definition with primary key(s). |
required |
items |
List[dict]
|
List of dicts with all columns of the model. |
required |
vendor |
Optional[Vendor]
|
Optional related Vendor instance used for logging and progress bar updates. |
None
|
session |
Optional[Session]
|
Optional database connections. When not provided, defaults to the |
None
|
progress |
Optional[Progress]
|
Optional progress bar to use instead of |
None
|
prefix |
str
|
Optional extra description for the model added in front of the model name in logs and progress bar updates. |
''
|
Source code in sc_crawler/insert.py
insert_items
#
Insert items into the related database table using bulk or merge.
Bulk insert is only supported with SQLite, other databases fall back to the default session.merge (slower) approach.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
SQLModel
|
An SQLModel table definition with primary key(s). |
required |
items |
List[dict]
|
List of dicts with all columns of the model. |
required |
vendor |
Optional[Vendor]
|
Optional related Vendor instance used for database connection, logging and progress bar updates. |
None
|
session |
Optional[Session]
|
Optional database connections. When not provided, defaults to the |
None
|
progress |
Optional[Progress]
|
Optional progress bar to use instead of |
None
|
prefix |
str
|
Optional extra description for the model added in front of the model name in logs and progress bar updates. |
''
|