MCPcopy Index your code
hub / github.com/pudo/dataset / insert

Method insert

dataset/table.py:134–162  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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,

Callers 15

insert_ignoreMethod · 0.95
upsertMethod · 0.95
insert_manyMethod · 0.45
test_insertFunction · 0.45
test_insert_jsonFunction · 0.45
test_weird_column_namesFunction · 0.45
test_cased_column_namesFunction · 0.45
test_deleteFunction · 0.45
test_find_oneFunction · 0.45
test_startswith_endswithFunction · 0.45
test_chunked_insertFunction · 0.45

Calls 2

_sync_columnsMethod · 0.95
_auto_commitMethod · 0.80

Tested by 15

test_insertFunction · 0.36
test_insert_jsonFunction · 0.36
test_weird_column_namesFunction · 0.36
test_cased_column_namesFunction · 0.36
test_deleteFunction · 0.36
test_find_oneFunction · 0.36
test_startswith_endswithFunction · 0.36
test_chunked_insertFunction · 0.36