mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
table.create_index(columns, index_name) method
This commit is contained in:
parent
70e1f831a0
commit
4427d2d96f
3 changed files with 81 additions and 0 deletions
|
|
@ -140,6 +140,19 @@ class Table:
|
|||
self.db.create_table(self.name, columns, pk=pk, foreign_keys=foreign_keys)
|
||||
self.exists = True
|
||||
|
||||
def create_index(self, columns, index_name=None):
|
||||
if index_name is None:
|
||||
index_name = "idx_{}_{}".format(
|
||||
self.name.replace(" ", "_"), "_".join(columns)
|
||||
)
|
||||
sql = """
|
||||
CREATE INDEX {index_name}
|
||||
ON {table_name} ({columns});
|
||||
""".format(
|
||||
index_name=index_name, table_name=self.name, columns=", ".join(columns)
|
||||
)
|
||||
self.db.conn.execute(sql)
|
||||
|
||||
def drop(self):
|
||||
return self.db.conn.execute("DROP TABLE {}".format(self.name))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue