Add a ``row`` dict by inserting it into the table. If ``ensure`` is set, any of the keys of the row are not table columns, they will be created automatically. During column creation, ``types`` will be checked for a key matching the name of a column to be created, an
(
self,
row: WriteRow,
ensure: bool | None = None,
types: dict[str, ColumnType] | None = None,
)
| 132 | return self._column_keys.get(key, name) |
| 133 | |
| 134 | def insert( |
| 135 | self, |
| 136 | row: WriteRow, |
| 137 | ensure: bool | None = None, |
| 138 | types: dict[str, ColumnType] | None = None, |
| 139 | ) -> Any: |
| 140 | """Add a ``row`` dict by inserting it into the table. |
| 141 | |
| 142 | If ``ensure`` is set, any of the keys of the row are not |
| 143 | table columns, they will be created automatically. |
| 144 | |
| 145 | During column creation, ``types`` will be checked for a key |
| 146 | matching the name of a column to be created, and the given |
| 147 | SQLAlchemy column type will be used. Otherwise, the type is |
| 148 | guessed from the row value, defaulting to a simple unicode |
| 149 | field. |
| 150 | :: |
| 151 | |
| 152 | data = dict(title='I am a banana!') |
| 153 | table.insert(data) |
| 154 | |
| 155 | Returns the inserted row's primary key. |
| 156 | """ |
| 157 | row = self._sync_columns(row, ensure, types=types) |
| 158 | res = self.db.executable.execute(self.table.insert().values(row)) |
| 159 | self.db._auto_commit() |
| 160 | if res.inserted_primary_key is not None and len(res.inserted_primary_key) > 0: |
| 161 | return res.inserted_primary_key[0] |
| 162 | return True |
| 163 | |
| 164 | def insert_ignore( |
| 165 | self, |