Skip to content

Commit

Permalink
Merge pull request #65 from kotolex/feature/version_1_0_7
Browse files Browse the repository at this point in the history
fix for release 2.1.2
  • Loading branch information
kotolex authored Nov 27, 2024
2 parents 28240ab + a8c212d commit d2320ac
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://pypi.org/project/surrealist/"><img src="https://img.shields.io/github/last-commit/kotolex/surrealist/master?style=flat-square"></a>
</p>

Surrealist is a Python tool to work with awesome [SurrealDB](https://docs.surrealdb.com/docs/intro) (support for latest version 2.1.1)
Surrealist is a Python tool to work with awesome [SurrealDB](https://docs.surrealdb.com/docs/intro) (support for latest version 2.1.2)

It is **synchronous** and **unofficial**, so if you need async AND/OR official client, go [here](https://github.com/surrealdb/surrealdb.py)

Expand All @@ -22,7 +22,7 @@ Works and tested on Ubuntu, macOS, Windows 10, can use python 3.8+ (including py
* only one small dependency (websocket-client), no need to pull a lot of libraries to your project
* fully documented
* well tested (on the latest Ubuntu, macOS and Windows 10)
* fully compatible with the latest version of SurrealDB (2.1.1), including [live queries](https://surrealdb.com/products/lq) and [change feeds](https://surrealdb.com/products/cf)
* fully compatible with the latest version of SurrealDB (2.1.2), including [live queries](https://surrealdb.com/products/lq) and [change feeds](https://surrealdb.com/products/cf)
* debug mode to see all that goes in and out if you need (using standard logging)
* iterator to handle big select queries
* QL-builder to explore, generate and use SurrealDB queries (explain, transaction etc.)
Expand Down Expand Up @@ -168,13 +168,14 @@ from surrealist import Database
# connects to Database (it is not connection)
with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db:
table = db.table("person") # switch to table level, no problem if it is not exists
print(table.count()) # 0, table is empty or not exists
# let's add record
# real query CREATE person:john SET status = "ACTIVE" RETURN id;
result = table.create("john").set(status="ACTIVE").returns("id").run()
# SurrealResult(id=9eb966a4-02fc-40ea-82ba-825d37254f43, status=OK, result=[{'id': 'person:john'}],
# query=CREATE person:john SET status = "ACTIVE" RETURN id;, code=None, time=110.3µs, additional_info={})
print(result)
print(table.count()) # 1 record
print(table.count()) # now one record
```
You can find QL examples [here](https://github.com/kotolex/surrealist/tree/master/examples/surreal_ql)

Expand Down
3 changes: 3 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Release Notes ##
**Version 1.0.7 (compatible with SurrealDB version 2.1.2):**
- fix tests and examples

**Version 1.0.6 (compatible with SurrealDB version 2.1.1):**
- versionstamp is now can be used in SINCE statement for SHOW
- by default, if no SINCE were specified Show statement generates SINCE 1
Expand Down
1 change: 1 addition & 0 deletions examples/surreal_ql/ql_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with Database("http://127.0.0.1:8000", 'test', 'test', credentials=("user_db", "user_db")) as db:
print(db.tables()) # [] cause database is empty
table = db.table("person") # even there is no such table yes it is OK to switch on it
print(table.count()) # and even get count of records which is 0 for non-existent table
# now let's create one record via set statement
result = table.create().set(name="Alex", age=30, active=True).run() # pay attention how we use keyword parameters
print(result.result) # [{'active': True, 'age': 30, 'id': 'person:wfulrb7dqml3vv7koqnb', 'name': 'Alex'}]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "surrealist"
version = "1.0.6"
version = "1.0.7"
description = "Python client for SurrealDB, latest SurrealDB version compatible, all features supported"
readme = "README.md"
authors = [{ name = "kotolex", email = "farofwell@gmail.com" }]
Expand Down
8 changes: 5 additions & 3 deletions tests/integration_tests/test_http_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,22 @@ def test_count(self):
with surreal.connect() as connection:
connection.use("test", "test")
res = connection.count("not_exists")
self.assertTrue(res.is_error(), res)
self.assertFalse(res.is_error())
self.assertEqual(0, res.result)
self.assertEqual("SELECT count() FROM not_exists GROUP ALL;", res.query)
count = connection.count("article").result
uid = get_random_series(6)
connection.create("article", {"author": uid, "title": uid, "text": uid})
new_count = connection.count("article").result
self.assertEqual(new_count, count + 1)

def test_count_is_error_if_wrong(self):
def test_count_is_zero_if_wrong(self):
surreal = Surreal(URL, credentials=('root', 'root'), use_http=True)
with surreal.connect() as connection:
connection.use("test", "test")
res = connection.count("wrong")
self.assertTrue(res.is_error())
self.assertFalse(res.is_error())
self.assertEqual(0, res.result)

def test_count_returns_fields(self):
surreal = Surreal(URL, credentials=('root', 'root'), use_http=True)
Expand Down
8 changes: 5 additions & 3 deletions tests/integration_tests/test_ws_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,22 @@ def test_count(self):
with surreal.connect() as connection:
connection.use("test", "test")
res = connection.count("not_exists")
self.assertTrue(res.is_error())
self.assertFalse(res.is_error())
self.assertEqual(0, res.result)
self.assertEqual("SELECT count() FROM not_exists GROUP ALL;", res.query)
count = connection.count("article").result
uid = get_random_series(6)
connection.create("article", {"author": uid, "title": uid, "text": uid})
new_count = connection.count("article").result
self.assertEqual(new_count, count + 1)

def test_count_is_error_if_wrong(self):
def test_count_is_zero_if_wrong(self):
surreal = Surreal(URL, credentials=('root', 'root'))
with surreal.connect() as connection:
connection.use("test", "test")
res = connection.count("wrong")
self.assertTrue(res.is_error())
self.assertFalse(res.is_error())
self.assertEqual(0, res.result)

def test_count_returns_fields(self):
surreal = Surreal(URL, credentials=('root', 'root'))
Expand Down

0 comments on commit d2320ac

Please sign in to comment.