Skip to content

Commit ae21f87

Browse files
authored
CBOR implementation and Native RPC (#116)
1 parent ffefd8a commit ae21f87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2002
-3459
lines changed

.cargo/config

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/stability.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ jobs:
2727

2828
- id: ruff
2929
if: always()
30-
<<<<<<< HEAD
31-
run: poetry run ruff --format=github python_package/surrealdb/
32-
33-
- id: Black
34-
if: always()
35-
run: poetry run black python_package/surrealdb/ --check --verbose --diff --color
36-
37-
- id: mypy
38-
if: always()
39-
run: poetry run mypy python_package/surrealdb/
40-
=======
4130
run: poetry run ruff check surrealdb/
4231

4332
- id: Black
@@ -47,4 +36,3 @@ jobs:
4736
- id: mypy
4837
if: always()
4938
run: poetry run mypy surrealdb/
50-
>>>>>>> 89bdd361d0a92f69deff137958279ab21161f00c

.github/workflows/unit_tests.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,3 @@ jobs:
3131
- name: Run Tests
3232
run: sh scripts/run_tests.sh
3333

34-
run-rust-unit-tests:
35-
needs: run-unit-tests
36-
runs-on: ubuntu-latest
37-
steps:
38-
- name: Checkout code
39-
uses: actions/checkout@v2
40-
41-
- name: Set up Rust
42-
uses: actions-rs/toolchain@v1
43-
with:
44-
toolchain: stable
45-
46-
- name: Build and Run Unit Tests
47-
run: cargo test

Cargo.toml

Lines changed: 0 additions & 39 deletions
This file was deleted.

docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ services:
1010
ports:
1111
- 8000:8000
1212

13+
surrealdb_200:
14+
image: surrealdb/surrealdb:v2.0.0
15+
command: "start"
16+
environment:
17+
- SURREAL_USER=root
18+
- SURREAL_PASS=root
19+
- SURREAL_LOG=trace
20+
ports:
21+
- 8200:8000
22+
1323
surrealdb_121:
1424
image: surrealdb/surrealdb:v1.2.1
1525
command: "start"

examples/basic_async_example.py

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,59 @@
11
from surrealdb import AsyncSurrealDB
22

3+
34
async def main():
45
"""Example of how to use the SurrealDB client."""
5-
db = AsyncSurrealDB("ws://localhost:8000/database/namespace")
6-
7-
await db.connect()
8-
9-
await db.signin({
10-
"username": "root",
11-
"password": "root",
12-
})
13-
14-
print("Using methods")
15-
print("create: " ,await db.create(
16-
"person",
17-
{
18-
"user": "me",
19-
"pass": "safe",
20-
"marketing": True,
21-
"tags": ["python", "documentation"],
22-
},
23-
))
24-
print("read: ", await db.select("person"))
25-
print("update: ", await db.update("person", {
26-
"user":"you",
27-
"pass":"very_safe",
28-
"marketing": False,
29-
"tags": ["Awesome"]
30-
}))
31-
print("delete: ", await db.delete("person"))
32-
33-
# You can also use the query method
34-
# doing all of the above and more in SurrealQl
35-
36-
# In SurrealQL you can do a direct insert
37-
# and the table will be created if it doesn't exist
38-
print("Using justawait db.query")
39-
print("create: ", await db.query("""
40-
insert into person {
41-
user: 'me',
42-
pass: 'very_safe',
43-
tags: ['python', 'documentation']
44-
};
45-
46-
"""))
47-
print("read: ", await db.query("select * from person"))
48-
49-
print("update: ", await db.query("""
50-
update person content {
51-
user: 'you',
52-
pass: 'more_safe',
53-
tags: ['awesome']
54-
};
55-
56-
"""))
57-
print( "delete: ", await db.query("delete person"))
6+
async with AsyncSurrealDB("ws://localhost:8000") as db:
7+
await db.use("test", "test")
8+
await db.sign_in("root", "root")
9+
10+
print("Using methods")
11+
print("create: ", await db.create(
12+
"person",
13+
{
14+
"user": "me",
15+
"pass": "safe",
16+
"marketing": True,
17+
"tags": ["python", "documentation"],
18+
},
19+
))
20+
print("read: ", await db.select("person"))
21+
print("update: ", await db.update("person", {
22+
"user": "you",
23+
"pass": "very_safe",
24+
"marketing": False,
25+
"tags": ["Awesome"]
26+
}))
27+
print("delete: ", await db.delete("person"))
28+
29+
# You can also use the query method
30+
# doing all of the above and more in SurrealQl
31+
32+
# In SurrealQL you can do a direct insert
33+
# and the table will be created if it doesn't exist
34+
print("Using justawait db.query")
35+
print("create: ", await db.query("""
36+
insert into person {
37+
user: 'me',
38+
pass: 'very_safe',
39+
tags: ['python', 'documentation']
40+
};
41+
42+
"""))
43+
print("read: ", await db.query("select * from person"))
44+
45+
print("update: ", await db.query("""
46+
update person content {
47+
user: 'you',
48+
pass: 'more_safe',
49+
tags: ['awesome']
50+
};
51+
52+
"""))
53+
print("delete: ", await db.query("delete person"))
54+
5855

5956
if __name__ == "__main__":
6057
import asyncio
6158

62-
asyncio.run(main())
59+
asyncio.run(main())

examples/basic_example.py

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,50 @@
11
from surrealdb import SurrealDB
22

3-
db = SurrealDB("ws://localhost:8000/database/namespace")
4-
5-
db.signin({
6-
"username": "root",
7-
"password": "root",
8-
})
9-
10-
print("Using methods")
11-
print("create: ", db.create(
12-
"person",
13-
{
14-
"user": "me",
15-
"pass": "safe",
16-
"marketing": True,
17-
"tags": ["python", "documentation"],
18-
},
19-
))
20-
print("read: ", db.select("person"))
21-
print("update: ", db.update("person", {
22-
"user":"you",
23-
"pass":"very_safe",
24-
"marketing": False,
25-
"tags": ["Awesome"]
26-
}))
27-
print("delete: ", db.delete("person"))
28-
29-
# You can also use the query method
30-
# doing all of the above and more in SurrealQl
31-
32-
# In SurrealQL you can do a direct insert
33-
# and the table will be created if it doesn't exist
34-
print("Using just db.query")
35-
print("create: ", db.query("""
36-
insert into person {
37-
user: 'me',
38-
pass: 'very_safe',
39-
tags: ['python', 'documentation']
40-
};
41-
42-
"""))
43-
print("read: ", db.query("select * from person"))
44-
45-
print("update: ", db.query("""
46-
update person content {
47-
user: 'you',
48-
pass: 'more_safe',
49-
tags: ['awesome']
50-
};
51-
52-
"""))
53-
print( "delete: ", db.query("delete person"))
3+
with SurrealDB("ws://localhost:8000") as db:
4+
db.use("test", "test")
5+
token = db.sign_in("root", "root")
6+
7+
print("Using methods")
8+
print("create: ", db.create(
9+
"person",
10+
{
11+
"user": "me",
12+
"pass": "safe",
13+
"marketing": True,
14+
"tags": ["python", "documentation"],
15+
},
16+
))
17+
print("read: ", db.select("person"))
18+
print("update: ", db.update("person", {
19+
"user": "you",
20+
"pass": "very_safe",
21+
"marketing": False,
22+
"tags": ["Awesome"]
23+
}))
24+
print("delete: ", db.delete("person"))
25+
26+
# You can also use the query method
27+
# doing all of the above and more in SurrealQl
28+
29+
# In SurrealQL you can do a direct insert
30+
# and the table will be created if it doesn't exist
31+
print("Using just db.query")
32+
print("create: ", db.query("""
33+
insert into person {
34+
user: 'me',
35+
pass: 'very_safe',
36+
tags: ['python', 'documentation']
37+
};
38+
39+
"""))
40+
print("read: ", db.query("select * from person"))
41+
42+
print("update: ", db.query("""
43+
update person content {
44+
user: 'you',
45+
pass: 'more_safe',
46+
tags: ['awesome']
47+
};
48+
49+
"""))
50+
print("delete: ", db.query("delete person"))

examples/notebook_example.ipynb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
"source": [
1717
"from surrealdb import AsyncSurrealDB\n",
1818
"\n",
19-
"db = AsyncSurrealDB(\"ws://localhost:8000/database/namespace\")\n",
19+
"db = AsyncSurrealDB(\"ws://localhost:8000\")\n",
2020
"\n",
2121
"await db.connect()\n",
2222
"\n",
23-
"await db.signin({\n",
24-
" \"username\": \"root\",\n",
25-
" \"password\": \"root\",\n",
26-
"})"
23+
"await db.use(\"test\", \"test\")\n",
24+
"\n",
25+
"await db.sign_in(\"root\", \"root\")"
2726
]
2827
},
2928
{

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1+
[tool.poetry]
2+
name = "surrealdb"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Maxwell Flitton <>", "Remi A <mail4remi@yahoo.com>"]
6+
readme = "README.md"
7+
18
[build-system]
29
requires = ["setuptools", "wheel", "setuptools-rust"]

0 commit comments

Comments
 (0)