rev-driver-changes

This commit is contained in:
Gal Shubeli 2025-08-14 15:44:05 +03:00
parent 43c4692f49
commit cd576a13aa
2 changed files with 14 additions and 32 deletions

View file

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import copy
import logging
from abc import ABC, abstractmethod
from collections.abc import Coroutine
@ -74,6 +75,16 @@ class GraphDriver(ABC):
def delete_all_indexes(self) -> Coroutine:
raise NotImplementedError()
def with_database(self, database: str) -> 'GraphDriver':
"""
Returns a shallow copy of this driver with a different default database.
Reuses the same connection (e.g. FalkorDB, Neo4j).
"""
cloned = copy.copy(self)
cloned._database = database
return cloned
@abstractmethod
async def build_indices_and_constraints(self, delete_existing: bool = False):
raise NotImplementedError()

View file

@ -170,38 +170,9 @@ class FalkorDriver(GraphDriver):
await self.client.connection.close()
async def delete_all_indexes(self) -> None:
result = await self.execute_query("CALL db.indexes()")
if not result:
return
records, _, _ = result
drop_tasks = []
for record in records:
label = record["label"]
entity_type = record["entitytype"]
for field_name, index_type in record["types"].items():
if "RANGE" in index_type:
drop_tasks.append(
self.execute_query(f"DROP INDEX ON :{label}({field_name})")
)
elif "FULLTEXT" in index_type:
if entity_type == "NODE":
drop_tasks.append(
self.execute_query(
f"DROP FULLTEXT INDEX FOR (n:{label}) ON (n.{field_name})"
)
)
elif entity_type == "RELATIONSHIP":
drop_tasks.append(
self.execute_query(
f"DROP FULLTEXT INDEX FOR ()-[e:{label}]-() ON (e.{field_name})"
)
)
if drop_tasks:
await asyncio.gather(*drop_tasks)
await self.execute_query(
'CALL db.indexes() YIELD name DROP INDEX name',
)
async def build_indices_and_constraints(self, delete_existing=False):
if delete_existing: