|
12 | 12 | from piccolo.columns.defaults.base import Default |
13 | 13 | from piccolo.query import ( |
14 | 14 | Alter, |
15 | | - Create, |
16 | 15 | Count, |
| 16 | + Create, |
17 | 17 | Delete, |
| 18 | + DropIndex, |
18 | 19 | Exists, |
19 | 20 | Insert, |
20 | 21 | Objects, |
|
23 | 24 | TableExists, |
24 | 25 | Update, |
25 | 26 | ) |
| 27 | +from piccolo.query.methods.create_index import CreateIndex, IndexMethod |
26 | 28 | from piccolo.querystring import QueryString, Unquoted |
27 | 29 | from piccolo.utils import _camel_to_snake |
28 | 30 |
|
@@ -399,7 +401,7 @@ def raw(cls, sql: str, *args: t.Any) -> Raw: |
399 | 401 | """ |
400 | 402 | Execute raw SQL queries on the underlying engine - use with caution! |
401 | 403 |
|
402 | | - await Band.raw('select * from band') |
| 404 | + await Band.raw('select * from band').run() |
403 | 405 |
|
404 | 406 | Or passing in parameters: |
405 | 407 |
|
@@ -478,7 +480,7 @@ def alter(cls) -> Alter: |
478 | 480 | """ |
479 | 481 | Used to modify existing tables and columns. |
480 | 482 |
|
481 | | - await Band.alter().rename_column(Band.popularity, 'rating') |
| 483 | + await Band.alter().rename_column(Band.popularity, 'rating').run() |
482 | 484 | """ |
483 | 485 | return Alter(table=cls) |
484 | 486 |
|
@@ -535,10 +537,32 @@ def update(cls, values: t.Dict[Column, t.Any] = {}) -> Update: |
535 | 537 |
|
536 | 538 | await Band.update().values( |
537 | 539 | {Band.name: "Spamalot"} |
538 | | - ).where(Band.name=="Pythonistas") |
| 540 | + ).where( |
| 541 | + Band.name=="Pythonistas" |
| 542 | + ).run() |
539 | 543 | """ |
540 | 544 | return Update(table=cls).values(values) |
541 | 545 |
|
| 546 | + @classmethod |
| 547 | + def create_index( |
| 548 | + cls, column: Column, method: IndexMethod = IndexMethod.btree, |
| 549 | + ) -> CreateIndex: |
| 550 | + """ |
| 551 | + Create a table index. |
| 552 | +
|
| 553 | + await Band.create_index(Band.name).run() |
| 554 | + """ |
| 555 | + return CreateIndex(table=cls, column=column, method=method) |
| 556 | + |
| 557 | + @classmethod |
| 558 | + def drop_index(cls, column: Column) -> DropIndex: |
| 559 | + """ |
| 560 | + Drop a table index. |
| 561 | +
|
| 562 | + await Band.drop_index(Band.name).run() |
| 563 | + """ |
| 564 | + return DropIndex(table=cls, column=column) |
| 565 | + |
542 | 566 | ########################################################################### |
543 | 567 |
|
544 | 568 | @classmethod |
|
0 commit comments