From 6c7ccd75b8b4adf833f5132240dea0d13057220e Mon Sep 17 00:00:00 2001 From: kotolex Date: Wed, 6 Nov 2024 15:18:15 +0500 Subject: [PATCH] Minor fixes for pylint and examples --- README.md | 11 +++++++++ ReleaseNotes.md | 6 ++++- examples/record_id.py | 6 ++--- examples/surreal_ql/define_user.py | 2 +- examples/surreal_ql/ql_alter_examples.py | 6 ++--- examples/surreal_ql/ql_create_examples.py | 7 +++--- examples/surreal_ql/ql_delete_examples.py | 8 +++---- examples/surreal_ql/ql_insert_examples.py | 10 ++++---- examples/surreal_ql/ql_live_examples.py | 2 +- examples/surreal_ql/ql_relate_examples.py | 2 +- examples/surreal_ql/ql_select_examples.py | 8 +++---- examples/surreal_ql/ql_update_examples.py | 15 ++++++------ examples/surreal_ql/ql_upsert_examples.py | 13 ++++++----- examples/surreal_ql/transaction.py | 23 ++++++++++--------- pylint.toml | 2 +- pyproject.toml | 16 +++++++++---- src/surrealist/connections/connection.py | 2 +- src/surrealist/connections/http_connection.py | 3 +++ src/surrealist/connections/pool.py | 4 ++++ src/surrealist/connections/ws_connection.py | 3 +++ src/surrealist/ql/statements/define_access.py | 10 ++------ .../ql/statements/define_index_statements.py | 2 -- src/surrealist/record_id.py | 19 +++++++++++---- 23 files changed, 110 insertions(+), 70 deletions(-) diff --git a/README.md b/README.md index 2d15614..27e1a7b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,15 @@ # README # +

+ +   + +   + +   + +   + +

Surrealist is a Python tool to work with awesome [SurrealDB](https://docs.surrealdb.com/docs/intro) (support for latest version 2.0.4) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index a716cf7..ce77f2f 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,7 +1,11 @@ ## Release Notes ## +**Version 1.0.5 (compatible with SurrealDB version 2.0.4):** +- minor examples fix +- minor pylint and readme fixes + **Version 1.0.4 (compatible with SurrealDB version 2.0.4):** - fix record ids bug (cause SDB since 2.0 not convert string to record_id) -- Readme [block for RecordId](https://github.com/kotolex/surrealist#Using_recordid) +- Readme [block for RecordId](https://github.com/kotolex/surrealist?tab=readme-ov-file#using-recordid) - examples [for RecordId](https://github.com/kotolex/surrealist/blob/master/examples/record_id.py) - create RecordId object to work with string or uid/ulid record_id - now all methods can use RecordId, but strings can be used too for compatibility diff --git a/examples/record_id.py b/examples/record_id.py index 8aef998..994efed 100644 --- a/examples/record_id.py +++ b/examples/record_id.py @@ -1,6 +1,6 @@ from surrealist import RecordId, get_uuid -# Please read https://github.com/kotolex/surrealist#Using_recordid +# Please read https://github.com/kotolex/surrealist?tab=readme-ov-file#using-recordid # Refer to https://surrealdb.com/docs/surrealql/datamodel/ids # You can create a RecordId from id in full form @@ -9,14 +9,14 @@ print(record_id.id_part) # tobie print(record_id.table_part) # person print(record_id.to_prefixed_string()) # r'person:tobie' -print(f"{record_id!r}") # RecordId('person:tobie') +print(record_id) # RecordId('person:tobie') # Same RecordId as above we can create with id and table record_id = RecordId('tobie', table='person') print(record_id.naive_id) # person:tobie print(record_id.id_part) # tobie print(record_id.table_part) # person print(record_id.to_prefixed_string()) # r'person:tobie' -print(f"{record_id!r}") # RecordId('person:tobie') +print(record_id) # RecordId('person:tobie') # Note! An exception will be raised if you try to create a RecordId in the wrong way # All examples below will raise an exception: diff --git a/examples/surreal_ql/define_user.py b/examples/surreal_ql/define_user.py index 1ca8e50..951054b 100644 --- a/examples/surreal_ql/define_user.py +++ b/examples/surreal_ql/define_user.py @@ -1,6 +1,6 @@ from surrealist import Database -with Database("http://127.0.0.1:8000", 'test', 'test', credentials=('user_db', 'user_db'), use_http=True) as db: +with Database("http://127.0.0.1:8000", 'test', 'test', credentials=('user_db', 'user_db')) as db: # on database object we can DEFINE USER # DEFINE USER new_user ON DATABASE PASSWORD '123456' ROLES OWNER; diff --git a/examples/surreal_ql/ql_alter_examples.py b/examples/surreal_ql/ql_alter_examples.py index 64c05bb..3fcddf0 100644 --- a/examples/surreal_ql/ql_alter_examples.py +++ b/examples/surreal_ql/ql_alter_examples.py @@ -9,15 +9,15 @@ with Database("http://127.0.0.1:8000", 'test', 'test', credentials=('user_db', 'user_db')) as db: # ALTER TABLE user SCHEMAFULL; - print(db.alter_table("user").schema_full()) + print(db.alter_table("user").schemafull()) # ALTER TABLE IF NOT EXISTS user SCHEMALESS; - print(db.alter_table("user").if_not_exists().schema_less()) + print(db.alter_table("user").if_not_exists().schemaless()) # ALTER TABLE user PERMISSIONS FOR create FULL; print(db.alter_table("user").permissions_for(create="FULL")) # ALTER TABLE user PERMISSIONS NONE COMMENT "text_of_comment"; print(db.alter_table("user").permissions_none().comment("text_of_comment")) # ALTER TABLE IF NOT EXISTS user SCHEMAFULL; - print(db.alter_table("user").if_not_exists().schema_full()) + print(db.alter_table("user").if_not_exists().schemafull()) diff --git a/examples/surreal_ql/ql_create_examples.py b/examples/surreal_ql/ql_create_examples.py index 85a0438..622025a 100644 --- a/examples/surreal_ql/ql_create_examples.py +++ b/examples/surreal_ql/ql_create_examples.py @@ -1,4 +1,4 @@ -from surrealist import Database +from surrealist import Database, RecordId # Please read https://docs.surrealdb.com/docs/surrealql/statements/create # here we represent analogs for string queries @@ -8,7 +8,8 @@ with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db: print(db.person.create()) # CREATE person; print(db.table("person").create().only()) # CREATE ONLY person; - print(db.table("person").create("tobie").only()) # CREATE ONLY person:tobie; + tobie = RecordId("tobie", table="person") # Pay attention how you should use RecordId + print(db.table("person").create(tobie).only()) # CREATE ONLY person:tobie; # CREATE person SET name = "Tobie", company = "SurrealDB", skills = ["Rust", "Go", "JavaScript"]; print(db.table("person").create().set(name="Tobie", company="SurrealDB", skills=["Rust", "Go", "JavaScript"])) @@ -20,7 +21,7 @@ print(db.table("person").create().set('name = "Tobie"', company="SurrealDB", skills=["Rust", "Go", "JavaScript"])) # CREATE person:tobie CONTENT {"name": "Tobie", "company": "SurrealDB", "skills": ["Rust"]}; - print(db.table("person").create("tobie").content({"name": "Tobie", "company": "SurrealDB", "skills": ["Rust"]})) + print(db.table("person").create(tobie).content({"name": "Tobie", "company": "SurrealDB", "skills": ["Rust"]})) # CREATE person SET age = 46, username = "john-smith" RETURN NONE; print(db.person.create().set(age=46, username="john-smith").return_none()) diff --git a/examples/surreal_ql/ql_delete_examples.py b/examples/surreal_ql/ql_delete_examples.py index 950c13b..b036e2d 100644 --- a/examples/surreal_ql/ql_delete_examples.py +++ b/examples/surreal_ql/ql_delete_examples.py @@ -5,11 +5,11 @@ # Notice: all queries below not executed, just generate representation. # To run it against SurrealDB, you need to use run method -with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("root", "root")) as db: +with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db: print(db.person.delete()) # DELETE person; - print(db.person.delete("tobie")) # DELETE person:tobie; - print(db.person.delete(RecordId("person:tobie"))) # DELETE person:tobie; - print(db.table("person").delete("tobie").only()) # DELETE ONLY person:tobie; + tobie = RecordId("tobie", table="person") # Pay attention how you should use RecordId + print(db.person.delete(tobie)) # DELETE person:tobie; + print(db.table("person").delete(tobie).only()) # DELETE ONLY person:tobie; # DELETE person WHERE age < 18 RETURN NONE TIMEOUT 10s PARALLEL; print(db.table("person").delete().where("age < 18").return_none().timeout("10s").parallel()) diff --git a/examples/surreal_ql/ql_insert_examples.py b/examples/surreal_ql/ql_insert_examples.py index 3b04a55..f75fcc1 100644 --- a/examples/surreal_ql/ql_insert_examples.py +++ b/examples/surreal_ql/ql_insert_examples.py @@ -1,4 +1,4 @@ -from surrealist import Database +from surrealist import Database, RecordId # Please read https://docs.surrealdb.com/docs/surrealql/statements/insert # here we represent analogs for string queries @@ -6,18 +6,20 @@ # Notice: all queries below not executed, just generate representation. # To run it against SurrealDB, you need to use run method with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db: + tobie = RecordId("tobie", table="person") # Pay attention how you should use RecordId + jaime = RecordId("jaime", table="person") # Pay attention how you should use RecordId data = { 'name': 'SurrealDB', 'founded': "2021-09-10", - 'founders': ['person:tobie', 'person:jaime'], + 'founders': [tobie, jaime], 'tags': ['big data', 'database'] } # INSERT INTO person {"name": "SurrealDB", "founded": "2021-09-10", "founders": ["person:tobie", "person:jaime"], # "tags": ["big data", "database"]}; print(db.person.insert(data)) - bulk = [{'id': "person:jaime", 'name': "Jaime", 'surname': "Morgan Hitchcock"}, - {'id': "person:tobie", 'name': "Tobie", 'surname': "Morgan Hitchcock"}] + bulk = [{'id': jaime, 'name': "Jaime", 'surname': "Morgan Hitchcock"}, + {'id': tobie, 'name': "Tobie", 'surname': "Morgan Hitchcock"}] # INSERT INTO person [{"id": "person:jaime", "name": "Jaime", "surname": "Morgan Hitchcock"}, # {"id": "person:tobie", "name": "Tobie", "surname": "Morgan Hitchcock"}]; print(db.person.insert(bulk)) diff --git a/examples/surreal_ql/ql_live_examples.py b/examples/surreal_ql/ql_live_examples.py index e471a05..5e5b360 100644 --- a/examples/surreal_ql/ql_live_examples.py +++ b/examples/surreal_ql/ql_live_examples.py @@ -5,7 +5,7 @@ # Notice: all queries below not executed, just generate representation. # To run it against SurrealDB, you need to use run method -with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("root", "root")) as db: +with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db: # print here - is a callback print(db.person.live(print)) # LIVE SELECT * FROM person; print(db.person.live(print, use_diff=True)) # LIVE SELECT DIFF FROM person; diff --git a/examples/surreal_ql/ql_relate_examples.py b/examples/surreal_ql/ql_relate_examples.py index 79271cd..deb1a78 100644 --- a/examples/surreal_ql/ql_relate_examples.py +++ b/examples/surreal_ql/ql_relate_examples.py @@ -5,7 +5,7 @@ # Notice: all queries below not executed, just generate representation. # To run it against SurrealDB, you need to use run method -with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("root", "root")) as db: +with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db: # Pay attention, we should use RELATE on database level, not on specific table # RELATE person:l19zjikkw1p1h9o6ixrg->wrote->article:8nkk6uj4yprt49z7y3zm; diff --git a/examples/surreal_ql/ql_select_examples.py b/examples/surreal_ql/ql_select_examples.py index a9f5845..514885b 100644 --- a/examples/surreal_ql/ql_select_examples.py +++ b/examples/surreal_ql/ql_select_examples.py @@ -8,11 +8,11 @@ with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db: print(db.table("person").select()) # SELECT * FROM person; print(db.table("person").select("*")) # SELECT * FROM person; - print(db.table("person").select().by_id("john")) # SELECT * FROM person:john; - print(db.table("person").select().by_id(RecordId("person:john"))) # SELECT * FROM person:john; + john = RecordId("john", table="person") # Pay attention how you should use RecordId + print(db.table("person").select().by_id(john)) # SELECT * FROM person:john; print(db.table("person").select("name", "age")) # SELECT name, age FROM person; - print(db.table("person").select("name", "age").by_id("john").only()) # SELECT name, age FROM ONLY person:john; - print(db.table("person").select(value="age").by_id("john")) # SELECT VALUE age FROM person:john; + print(db.table("person").select("name", "age").by_id(john).only()) # SELECT name, age FROM ONLY person:john; + print(db.table("person").select(value="age").by_id(john)) # SELECT VALUE age FROM person:john; # SELECT *, (SELECT * FROM events WHERE type = 'activity' LIMIT 5) AS history FROM person; print(db.table("person").select("*", alias=[("history", "(SELECT * FROM events WHERE type = 'activity' LIMIT 5)")])) diff --git a/examples/surreal_ql/ql_update_examples.py b/examples/surreal_ql/ql_update_examples.py index 4a8aa39..c698bde 100644 --- a/examples/surreal_ql/ql_update_examples.py +++ b/examples/surreal_ql/ql_update_examples.py @@ -1,4 +1,4 @@ -from surrealist import Database +from surrealist import Database, RecordId # Please read https://docs.surrealdb.com/docs/surrealql/statements/update # here we represent analogs for string queries @@ -7,7 +7,8 @@ # To run it against SurrealDB, you need to use run method with Database("http://127.0.0.1:8000", 'test', 'test', credentials=('user_db', 'user_db')) as db: print(db.table("person").update()) # UPDATE person; - print(db.table("person").update("tobie").only()) # UPDATE ONLY person:tobie; + tobie = RecordId("tobie", table="person") # Pay attention how you should use RecordId + print(db.table("person").update(tobie).only()) # UPDATE ONLY person:tobie; # UPDATE person SET active = true WHERE age < 18 RETURN NONE TIMEOUT 10s PARALLEL; print(db.table("person").update().set(active=True).where("age < 18").return_none().timeout("10s").parallel()) @@ -22,17 +23,17 @@ print(db.city.update().set(rank=4, population=9541000).where("name = 'London'")) # UPDATE ONLY person:tobie SET name = "Tobie", company = "SurrealDB", skills = ["Rust", "Go", "JavaScript"]; - print(db.table("person").update("tobie").only().set(name="Tobie", company="SurrealDB", - skills=['Rust', 'Go', 'JavaScript'])) + print(db.table("person").update(tobie).only().set(name="Tobie", company="SurrealDB", + skills=['Rust', 'Go', 'JavaScript'])) data = {'name': 'Tobie', 'company': 'SurrealDB', 'skills': ['Rust', 'Go', 'JavaScript']} # UPDATE person:tobie CONTENT {"name": "Tobie", "company": "SurrealDB", "skills": ["Rust", "Go", "JavaScript"]}; - print(db.person.update("tobie").content(data)) + print(db.person.update(tobie).content(data)) data = [{"op": "add", "path": "Engineering", "value": "true"}] # UPDATE person:tobie PATCH [{"op": "add", "path": "Engineering", "value": "true"}]; - print(db.person.update("tobie").patch(data)) + print(db.person.update(tobie).patch(data)) data = {'settings': {'marketing': True}} # UPDATE person:tobie MERGE {"settings": {"marketing": true}}; - print(db.person.update("tobie").merge(data)) + print(db.person.update(tobie).merge(data)) diff --git a/examples/surreal_ql/ql_upsert_examples.py b/examples/surreal_ql/ql_upsert_examples.py index ef07983..c00dec7 100644 --- a/examples/surreal_ql/ql_upsert_examples.py +++ b/examples/surreal_ql/ql_upsert_examples.py @@ -1,4 +1,4 @@ -from surrealist import Database +from surrealist import Database, RecordId # Please read https://docs.surrealdb.com/docs/surrealql/statements/upsert # here we represent analogs for string queries @@ -7,7 +7,8 @@ # To run it against SurrealDB, you need to use run method with Database("http://127.0.0.1:8000", 'test', 'test', credentials=('user_db', 'user_db')) as db: print(db.table("person").upsert()) # UPSERT person; - print(db.table("person").upsert("tobie").only()) # UPSERT ONLY person:tobie; + tobie = RecordId("tobie", table="person") # Pay attention how you should use RecordId + print(db.table("person").upsert(tobie).only()) # UPSERT ONLY person:tobie; # UPSERT person SET active = true WHERE age < 18 RETURN NONE TIMEOUT 10s PARALLEL; print(db.table("person").upsert().set(active=True).where("age < 18").return_none().timeout("10s").parallel()) @@ -22,17 +23,17 @@ print(db.city.upsert().set(rank=4, population=9541000).where("name = 'London'")) # UPSERT ONLY person:tobie SET name = "Tobie", company = "SurrealDB", skills = ["Rust", "Go", "JavaScript"]; - print(db.table("person").upsert("tobie").only().set(name="Tobie", company="SurrealDB", + print(db.table("person").upsert(tobie).only().set(name="Tobie", company="SurrealDB", skills=['Rust', 'Go', 'JavaScript'])) data = {'name': 'Tobie', 'company': 'SurrealDB', 'skills': ['Rust', 'Go', 'JavaScript']} # UPSERT person:tobie CONTENT {"name": "Tobie", "company": "SurrealDB", "skills": ["Rust", "Go", "JavaScript"]}; - print(db.person.upsert("tobie").content(data)) + print(db.person.upsert(tobie).content(data)) data = [{"op": "add", "path": "Engineering", "value": "true"}] # UPSERT person:tobie PATCH [{"op": "add", "path": "Engineering", "value": "true"}]; - print(db.person.upsert("tobie").patch(data)) + print(db.person.upsert(tobie).patch(data)) data = {'settings': {'marketing': True}} # UPSERT person:tobie MERGE {"settings": {"marketing": true}}; - print(db.person.upsert("tobie").merge(data)) + print(db.person.upsert(tobie).merge(data)) diff --git a/examples/surreal_ql/transaction.py b/examples/surreal_ql/transaction.py index 3af9b59..9f18ecb 100644 --- a/examples/surreal_ql/transaction.py +++ b/examples/surreal_ql/transaction.py @@ -1,4 +1,4 @@ -from surrealist import Database +from surrealist import Database, RecordId # we connect to a database via Database object with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db: @@ -7,23 +7,24 @@ book = db.table("book") counter = db.table("counter") # we create queries here but not run it! - create_author = author.create().content({"name": "john", "id": "john"}) - create_book = book.create().content({"title": "Title", "author": "author:john"}) # book will relate to author - counter_inc = counter.update("author_count").set("count +=1") # increment counter + john = RecordId("johnny", table="author") # Pay attention how you should use RecordId + author_count = RecordId("authorcount", table="counter") # Pay attention how you should use RecordId + create_author = author.create().content({"name": "john", "id": john}) + create_book = book.create().content({"title": "Title", "author": john}) # book will relate to author + counter_inc = counter.upsert(author_count).set("count +=1") # increment counter # on transactions see https://docs.surrealdb.com/docs/surrealql/transactions transaction = db.transaction([create_author, create_book, counter_inc]) print(transaction) # BEGIN TRANSACTION; # - # CREATE author CONTENT {"name": "john", "id": "john"}; - # CREATE book CONTENT {"title": "Title", "author": "author:john"}; - # UPDATE counter:author_count SET count +=1; + # CREATE author CONTENT {"name": "john", "id": author:johnny}; + # CREATE book CONTENT {"title": "Title", "author": author:johnny}; + # UPDATE counter:authorcount SET count +=1; # # COMMIT TRANSACTION; print(transaction.run().result) - # [{'result': [{'id': 'author:john', 'name': 'john'}], 'status': 'OK', 'time': '278.709µs'}, - # {'result': [{'author': 'author:john', 'id': 'book:5tyy73v17xqdk24yvj3c', 'title': 'Title'}], - # 'status': 'OK', 'time': '53.875µs'}, - # {'result': [{'count': 1, 'id': 'counter:author_count'}], 'status': 'OK', 'time': '53.667µs'}] + # [{'result': [{'id': 'author:johnny', 'name': 'john'}], 'status': 'OK', 'time': '115.9µs'}, + # {'result': [{'author': 'author:johnny', 'id': 'book:0yhz1i69d4ifocips9jk', 'title': 'Title'}], 'status': 'OK', 'time': '312.1µs'}, + # {'result': [{'count': 1, 'id': 'counter:authorcount'}], 'status': 'OK', 'time': '263.4µs'}] diff --git a/pylint.toml b/pylint.toml index 2c114ad..e6d83bf 100644 --- a/pylint.toml +++ b/pylint.toml @@ -274,7 +274,7 @@ max-returns = 6 max-statements = 50 # Minimum number of public methods for a class (see R0903). -min-public-methods = 2 +min-public-methods = 1 [tool.pylint.exceptions] # Exceptions that will emit a warning when caught. diff --git a/pyproject.toml b/pyproject.toml index 274de2c..5762bae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "surrealist" -version = "1.0.4" +version = "1.0.5" description = "Python client for SurrealDB, latest SurrealDB version compatible, all features supported" readme = "README.md" authors = [{ name = "kotolex", email = "farofwell@gmail.com" }] @@ -12,13 +12,21 @@ license = { file = "LICENSE" } classifiers = [ "License :: OSI Approved :: MIT License", "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + "Intended Audience :: Education", "Topic :: Software Development", "Topic :: Database", - "Programming Language :: Python", - "Programming Language :: Python :: 3", + "Topic :: Software Development :: Libraries", + "Development Status :: 5 - Production/Stable", "Operating System :: OS Independent", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] -keywords = ["surreal", "python", "Surreal", "SurrealDB", "surrealist", "database", "surrealdb"] +keywords = ["surreal", "python", "Surreal", "SurrealDB", "surrealist", "database", "surrealdb", "surrealdb.py"] dependencies = [ "websocket-client", ] diff --git a/src/surrealist/connections/connection.py b/src/surrealist/connections/connection.py index d6b6000..a6f132c 100644 --- a/src/surrealist/connections/connection.py +++ b/src/surrealist/connections/connection.py @@ -298,7 +298,7 @@ def use(self, namespace: str, database: Optional[str] = None) -> SurrealResult: @abstractmethod def transport(self) -> Transport: """ - This method returns the current transport + This method returns the transport type for the current connection Refer to: https://github.com/kotolex/surrealist?tab=readme-ov-file#transports """ diff --git a/src/surrealist/connections/http_connection.py b/src/surrealist/connections/http_connection.py index a9a5a2c..0365cd8 100644 --- a/src/surrealist/connections/http_connection.py +++ b/src/surrealist/connections/http_connection.py @@ -63,6 +63,9 @@ def _sign(self, credentials, db_params, url): f"Refer to https://docs.surrealdb.com/docs/introduction/start") def transport(self) -> Transport: + """ + Returns the transport type for http connection + """ return Transport.HTTP @connected diff --git a/src/surrealist/connections/pool.py b/src/surrealist/connections/pool.py index 66437f8..8d9b1f2 100644 --- a/src/surrealist/connections/pool.py +++ b/src/surrealist/connections/pool.py @@ -61,6 +61,10 @@ def __init__(self, first_connection: Connection, url: str, namespace: Optional[s self._start() def transport(self) -> Transport: + """ + Returns the transport type of the underlying connections + :return: Transport enum member + """ return Transport.HTTP if self._options["use_http"] else Transport.WEBSOCKET @property diff --git a/src/surrealist/connections/ws_connection.py b/src/surrealist/connections/ws_connection.py index 893777c..49905b3 100644 --- a/src/surrealist/connections/ws_connection.py +++ b/src/surrealist/connections/ws_connection.py @@ -96,6 +96,9 @@ def _use_or_sign_on_params(self, credentials): self._token = signin_result.result def transport(self) -> Transport: + """ + Returns the transport type for websocket connection + """ return Transport.WEBSOCKET @connected diff --git a/src/surrealist/ql/statements/define_access.py b/src/surrealist/ql/statements/define_access.py index b556e09..e568c84 100644 --- a/src/surrealist/ql/statements/define_access.py +++ b/src/surrealist/ql/statements/define_access.py @@ -243,16 +243,10 @@ def _clean_str(self): exists = " OVERWRITE" sin = "" if self._signin: - if isinstance(self._signin, str): - sin = f" SIGNIN {self._signin}" - else: - sin = f" SIGNIN {self._signin._clean_str()}" + sin = f" SIGNIN {self._signin}" if isinstance(self._signin, str) else f" SIGNIN {self._signin._clean_str()}" sup = "" if self._signup: - if isinstance(self._signup, str): - sup = f" SIGNUP {self._signup}" - else: - sup = f" SIGNUP {self._signup._clean_str()}" + sup = f" SIGNUP {self._signup}" if isinstance(self._signup, str) else f" SIGNUP {self._signup._clean_str()}" access = "" if self._algo: access = f" ALGORITHM {self._algo[0].name} KEY '{self._algo[1]}'" diff --git a/src/surrealist/ql/statements/define_index_statements.py b/src/surrealist/ql/statements/define_index_statements.py index bc14372..e65c6f7 100644 --- a/src/surrealist/ql/statements/define_index_statements.py +++ b/src/surrealist/ql/statements/define_index_statements.py @@ -13,8 +13,6 @@ class Concurrently(FinishedStatement): Refer to: https://surrealdb.com/docs/surrealdb/surrealql/statements/define/indexes#using-concurrently-clause """ - def __init__(self, statement: Statement): - super().__init__(statement) def _clean_str(self): return f"{self._statement._clean_str()} CONCURRENTLY" diff --git a/src/surrealist/record_id.py b/src/surrealist/record_id.py index 0ac61ec..21daea4 100644 --- a/src/surrealist/record_id.py +++ b/src/surrealist/record_id.py @@ -11,7 +11,7 @@ class RecordId: This class is a wrapper for record_id of SurrealDB About record_ids: https://surrealdb.com/docs/surrealql/datamodel/ids - Refer to: https://github.com/kotolex/surrealist#Using_recordid + Refer to: https://github.com/kotolex/surrealist?tab=readme-ov-file#using-recordid Examples: https://github.com/kotolex/surrealist/blob/master/examples/record_id.py """ @@ -40,16 +40,25 @@ def __repr__(self): @property def id_part(self) -> str: + """ + Returns id part of record_id, for "table:id" it returns "id" + """ return self._id_part - @property - def naive_id(self) -> str: - return self._naive_id - @property def table_part(self) -> str: + """ + Returns table part of record_id, for "table:id" it returns "table" + """ return self._table_part + @property + def naive_id(self) -> str: + """ + Returns naive record_id, without any special braces, e.g. 'table:id' + """ + return self._naive_id + def to_valid_string(self) -> str: """ Checks and adds special braces if id is not in simple form(a..zA..Z0-9), otherwise just returns naive_id