-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
517 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import asyncio | ||
|
||
from surrealdb import AsyncSurrealDB | ||
|
||
|
||
async def main(): | ||
async with AsyncSurrealDB(url="ws://localhost:8000") as db: | ||
# Sign up a new user | ||
token = await db.sign_up(username="new_user", password="secure_password") | ||
print(f"New User Token: {token}") | ||
|
||
# Sign in as an existing user | ||
token = await db.sign_in(username="existing_user", password="secure_password") | ||
print(f"Signed In Token: {token}") | ||
|
||
# Authenticate using a token | ||
await db.authenticate(token=token) | ||
print("Authentication successful!") | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import asyncio | ||
|
||
from surrealdb import AsyncSurrealDB | ||
|
||
|
||
async def main(): | ||
db = AsyncSurrealDB("ws://localhost:8000") | ||
await db.connect() | ||
await db.use("example_ns", "example_db") | ||
await db.sign_in("root", "root") | ||
|
||
# Insert a record | ||
new_user = {"name": "Alice", "age": 30} | ||
inserted_record = await db.insert("users", new_user) | ||
print(f"Inserted Record: {inserted_record}") | ||
|
||
# Retrieve the record | ||
retrieved_users = await db.select("users") | ||
print(f"Retrieved Users: {retrieved_users}") | ||
|
||
await db.close() | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import asyncio | ||
from surrealdb import AsyncSurrealDB | ||
|
||
|
||
async def main(): | ||
async with AsyncSurrealDB(url="ws://localhost:8000") as db: | ||
await db.sign_in("root", "root") | ||
await db.use("test", "test") | ||
|
||
query = "SELECT * FROM users WHERE age > min_age;" | ||
variables = {"min_age": 25} | ||
|
||
results = await db.query(query, variables) | ||
print(f"Query Results: {results}") | ||
|
||
|
||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import asyncio | ||
|
||
from surrealdb import AsyncSurrealDB | ||
|
||
async def main(): | ||
async with AsyncSurrealDB("ws://localhost:8000") as db: | ||
db.sign_in("root", "root") | ||
db.use("example_ns", "example_db") | ||
|
||
upsert_data = {"name": "Charlie", "age": 35} | ||
result = db.upsert("users", upsert_data) | ||
print(f"Upsert Result: {result}") | ||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from surrealdb import SurrealDB | ||
|
||
|
||
def main(): | ||
with SurrealDB(url="ws://localhost:8000") as db: | ||
# Sign up a new user | ||
token = db.sign_up(username="new_user", password="secure_password") | ||
print(f"New User Token: {token}") | ||
|
||
# Sign in as an existing user | ||
token = db.sign_in(username="existing_user", password="secure_password") | ||
print(f"Signed In Token: {token}") | ||
|
||
# Authenticate using a token | ||
db.authenticate(token=token) | ||
print("Authentication successful!") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.