insert
Insert query builder.
InsertQuery
InsertQuery is used to insert data into a table.
It is generic over the Table being inserted into, and the database being used.
InsertQuery is never used directly, but always returned by a Db instance.
It returns an InsertQueryReady instance once values() has been called.
from embar.db.pg import PgDb
from embar.query.insert import InsertQuery
db = PgDb(None)
insert = db.insert(None)
assert isinstance(insert, InsertQuery)
Source code in src/embar/query/insert.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
__init__(table, db)
Create a new InsertQuery instance.
Source code in src/embar/query/insert.py
36 37 38 39 40 41 | |
values(*items)
Load a sequence of items into the table.
Source code in src/embar/query/insert.py
43 44 45 46 47 | |
InsertQueryReady
InsertQueryReady is an insert query that is ready to be awaited or run.
Source code in src/embar/query/insert.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 | |
__await__()
async users should construct their query and await it.
non-async users have the run() convenience method below.
Source code in src/embar/query/insert.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
__init__(table, db, items)
Create a new InsertQueryReady instance.
Source code in src/embar/query/insert.py
60 61 62 63 64 65 66 | |
run()
run() -> None
run() -> InsertQueryReady[T, Db]
Run the query against the underlying DB.
Convenience method for those not using async. But still works if awaited.
Source code in src/embar/query/insert.py
102 103 104 105 106 107 108 109 110 111 112 | |
sql()
Create the SQL query and binding parameters (psycopg format) for the query.
from embar.column.common import Text
from embar.table import Table
from embar.query.insert import InsertQueryReady
class MyTable(Table):
my_col: Text = Text()
row = MyTable(my_col="foo")
insert = InsertQueryReady(db=None, table=MyTable, items=[row])
query = insert.sql()
assert query.sql == 'INSERT INTO "my_table" ("my_col") VALUES (%(my_col)s)'
assert query.many_params == [{'my_col': 'foo'}]
Source code in src/embar/query/insert.py
114 115 116 117 118 119 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 | |
InsertQueryReturning
InsertQueryReturning is an insert query that will return what it inserts.
Source code in src/embar/query/insert.py
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
__await__()
async users should construct their query and await it.
non-async users have the run() convenience method below.
Source code in src/embar/query/insert.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
__init__(table, db, items, on_conflict)
Create a new InsertQueryReturning instance.
Source code in src/embar/query/insert.py
165 166 167 168 169 170 171 172 | |
run()
run() -> list[T]
run() -> InsertQueryReturning[T, Db]
Run the query against the underlying DB.
Convenience method for those not using async. But still works if awaited.
Source code in src/embar/query/insert.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
sql()
Create the SQL query and binding parameters (psycopg format) for the query.
Source code in src/embar/query/insert.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |