insert
sc_crawler.insert
#
Functions:
| Name | Description |
|---|---|
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. |
bulk_insert_items |
Bulk inserts items into a SQLModel table with |
insert_items |
Insert items into the related database table using bulk or merge. |
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. |
''
|
Source code in sc_crawler/insert.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |