Skip to content

Commit 5a68262

Browse files
committed
add drop_table
1 parent 555b9a2 commit 5a68262

File tree

3 files changed

+76
-14
lines changed

3 files changed

+76
-14
lines changed

nbs/00_vector.ipynb

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@
187187
"\n",
188188
" def delete_all_query(self):\n",
189189
" return \"TRUNCATE {table_name};\".format(table_name=self._quote_ident(self.table_name))\n",
190+
"\n",
191+
" def drop_table_query(self):\n",
192+
" return \"DROP TABLE IF EXISTS {table_name};\".format(table_name=self._quote_ident(self.table_name))\n",
190193
" \n",
191194
" def create_ivfflat_index_query(self, num_records):\n",
192195
" \"\"\"\n",
@@ -411,6 +414,17 @@
411414
" query = self.builder.delete_all_query()\n",
412415
" async with await self.connect() as pool:\n",
413416
" await pool.execute(query)\n",
417+
" \n",
418+
" async def drop_table(self):\n",
419+
" \"\"\"\n",
420+
" Drops the table\n",
421+
"\n",
422+
" Returns:\n",
423+
" None\n",
424+
" \"\"\"\n",
425+
" query = self.builder.drop_table_query()\n",
426+
" async with await self.connect() as pool:\n",
427+
" await pool.execute(query)\n",
414428
"\n",
415429
" async def _get_approx_count(self):\n",
416430
" \"\"\"\n",
@@ -476,7 +490,7 @@
476490
"text/markdown": [
477491
"---\n",
478492
"\n",
479-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
493+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L256){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
480494
"\n",
481495
"### Async.create_tables\n",
482496
"\n",
@@ -490,7 +504,7 @@
490504
"text/plain": [
491505
"---\n",
492506
"\n",
493-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
507+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L256){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
494508
"\n",
495509
"### Async.create_tables\n",
496510
"\n",
@@ -521,7 +535,7 @@
521535
"text/markdown": [
522536
"---\n",
523537
"\n",
524-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
538+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L256){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
525539
"\n",
526540
"### Async.create_tables\n",
527541
"\n",
@@ -535,7 +549,7 @@
535549
"text/plain": [
536550
"---\n",
537551
"\n",
538-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L248){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
552+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L256){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
539553
"\n",
540554
"### Async.create_tables\n",
541555
"\n",
@@ -566,7 +580,7 @@
566580
"text/markdown": [
567581
"---\n",
568582
"\n",
569-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L311){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
583+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L319){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
570584
"\n",
571585
"### Async.search\n",
572586
"\n",
@@ -582,7 +596,7 @@
582596
"text/plain": [
583597
"---\n",
584598
"\n",
585-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L311){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
599+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L319){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
586600
"\n",
587601
"### Async.search\n",
588602
"\n",
@@ -702,7 +716,9 @@
702716
"\n",
703717
"\n",
704718
"await vec.delete_all()\n",
705-
"assert await vec.table_is_empty()"
719+
"assert await vec.table_is_empty()\n",
720+
"\n",
721+
"await vec.drop_table()"
706722
]
707723
},
708724
{
@@ -865,6 +881,18 @@
865881
" with conn.cursor() as cur:\n",
866882
" cur.execute(query)\n",
867883
"\n",
884+
" def drop_table(self):\n",
885+
" \"\"\"\n",
886+
" Drops the table\n",
887+
"\n",
888+
" Returns:\n",
889+
" None\n",
890+
" \"\"\"\n",
891+
" query = self.builder.drop_table_query()\n",
892+
" with self.connect() as conn:\n",
893+
" with conn.cursor() as cur:\n",
894+
" cur.execute(query)\n",
895+
"\n",
868896
" def _get_approx_count(self):\n",
869897
" \"\"\"\n",
870898
" Retrieves an approximate count of records in the table.\n",
@@ -938,7 +966,7 @@
938966
"text/markdown": [
939967
"---\n",
940968
"\n",
941-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L438){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
969+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L446){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
942970
"\n",
943971
"### Sync.create_tables\n",
944972
"\n",
@@ -952,7 +980,7 @@
952980
"text/plain": [
953981
"---\n",
954982
"\n",
955-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L438){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
983+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L446){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
956984
"\n",
957985
"### Sync.create_tables\n",
958986
"\n",
@@ -983,7 +1011,7 @@
9831011
"text/markdown": [
9841012
"---\n",
9851013
"\n",
986-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L419){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1014+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L427){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
9871015
"\n",
9881016
"### Sync.upsert\n",
9891017
"\n",
@@ -1000,7 +1028,7 @@
10001028
"text/plain": [
10011029
"---\n",
10021030
"\n",
1003-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L419){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1031+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L427){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
10041032
"\n",
10051033
"### Sync.upsert\n",
10061034
"\n",
@@ -1034,7 +1062,7 @@
10341062
"text/markdown": [
10351063
"---\n",
10361064
"\n",
1037-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L507){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1065+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L515){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
10381066
"\n",
10391067
"### Sync.search\n",
10401068
"\n",
@@ -1055,7 +1083,7 @@
10551083
"text/plain": [
10561084
"---\n",
10571085
"\n",
1058-
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L507){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
1086+
"[source](https://github.com/timescale/python-vector/blob/main/timescale_vector/client.py#L515){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
10591087
"\n",
10601088
"### Sync.search\n",
10611089
"\n",
@@ -1187,7 +1215,9 @@
11871215
"assert rec[0][SEARCH_RESULT_DISTANCE_IDX] == 0.0009438353921149556\n",
11881216
"\n",
11891217
"vec.delete_all()\n",
1190-
"assert vec.table_is_empty()"
1218+
"assert vec.table_is_empty()\n",
1219+
"\n",
1220+
"vec.drop_table()"
11911221
]
11921222
},
11931223
{

timescale_vector/_modidx.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
'timescale_vector/client.py'),
2323
'timescale_vector.client.Async.drop_embedding_index': ( 'vector.html#async.drop_embedding_index',
2424
'timescale_vector/client.py'),
25+
'timescale_vector.client.Async.drop_table': ( 'vector.html#async.drop_table',
26+
'timescale_vector/client.py'),
2527
'timescale_vector.client.Async.search': ('vector.html#async.search', 'timescale_vector/client.py'),
2628
'timescale_vector.client.Async.table_is_empty': ( 'vector.html#async.table_is_empty',
2729
'timescale_vector/client.py'),
@@ -39,6 +41,8 @@
3941
'timescale_vector/client.py'),
4042
'timescale_vector.client.QueryBuilder.drop_embedding_index_query': ( 'vector.html#querybuilder.drop_embedding_index_query',
4143
'timescale_vector/client.py'),
44+
'timescale_vector.client.QueryBuilder.drop_table_query': ( 'vector.html#querybuilder.drop_table_query',
45+
'timescale_vector/client.py'),
4246
'timescale_vector.client.QueryBuilder.get_approx_count_query': ( 'vector.html#querybuilder.get_approx_count_query',
4347
'timescale_vector/client.py'),
4448
'timescale_vector.client.QueryBuilder.get_create_query': ( 'vector.html#querybuilder.get_create_query',
@@ -67,6 +71,8 @@
6771
'timescale_vector/client.py'),
6872
'timescale_vector.client.Sync.drop_embedding_index': ( 'vector.html#sync.drop_embedding_index',
6973
'timescale_vector/client.py'),
74+
'timescale_vector.client.Sync.drop_table': ( 'vector.html#sync.drop_table',
75+
'timescale_vector/client.py'),
7076
'timescale_vector.client.Sync.search': ('vector.html#sync.search', 'timescale_vector/client.py'),
7177
'timescale_vector.client.Sync.table_is_empty': ( 'vector.html#sync.table_is_empty',
7278
'timescale_vector/client.py'),

timescale_vector/client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def drop_embedding_index_query(self):
112112

113113
def delete_all_query(self):
114114
return "TRUNCATE {table_name};".format(table_name=self._quote_ident(self.table_name))
115+
116+
def drop_table_query(self):
117+
return "DROP TABLE IF EXISTS {table_name};".format(table_name=self._quote_ident(self.table_name))
115118

116119
def create_ivfflat_index_query(self, num_records):
117120
"""
@@ -276,6 +279,17 @@ async def delete_all(self, drop_index=True):
276279
query = self.builder.delete_all_query()
277280
async with await self.connect() as pool:
278281
await pool.execute(query)
282+
283+
async def drop_table(self):
284+
"""
285+
Drops the table
286+
287+
Returns:
288+
None
289+
"""
290+
query = self.builder.drop_table_query()
291+
async with await self.connect() as pool:
292+
await pool.execute(query)
279293

280294
async def _get_approx_count(self):
281295
"""
@@ -469,6 +483,18 @@ def delete_all(self, drop_index=True):
469483
with conn.cursor() as cur:
470484
cur.execute(query)
471485

486+
def drop_table(self):
487+
"""
488+
Drops the table
489+
490+
Returns:
491+
None
492+
"""
493+
query = self.builder.drop_table_query()
494+
with self.connect() as conn:
495+
with conn.cursor() as cur:
496+
cur.execute(query)
497+
472498
def _get_approx_count(self):
473499
"""
474500
Retrieves an approximate count of records in the table.

0 commit comments

Comments
 (0)