-
Notifications
You must be signed in to change notification settings - Fork 57
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
10 changed files
with
217 additions
and
158 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from surrealdb import AsyncSurrealDB | ||
|
||
|
||
async def main(): | ||
"""Example of how to use the SurrealDB client.""" | ||
async with AsyncSurrealDB("ws://localhost:8000") as db: | ||
await db.sign_in("root", "root") | ||
await db.use("test", "test") | ||
|
||
print("Using methods") | ||
print("create: ", await db.create( | ||
"person", | ||
{ | ||
"user": "me", | ||
"pass": "safe", | ||
"marketing": True, | ||
"tags": ["python", "documentation"], | ||
}, | ||
)) | ||
print("read: ", await db.select("person")) | ||
print("update: ", await db.update("person", { | ||
"user": "you", | ||
"pass": "very_safe", | ||
"marketing": False, | ||
"tags": ["Awesome"] | ||
})) | ||
print("delete: ", await db.delete("person")) | ||
|
||
# You can also use the query method | ||
# doing all of the above and more in SurrealQl | ||
|
||
# In SurrealQL you can do a direct insert | ||
# and the table will be created if it doesn't exist | ||
print("Using justawait db.query") | ||
print("create: ", await db.query(""" | ||
insert into person { | ||
user: 'me', | ||
pass: 'very_safe', | ||
tags: ['python', 'documentation'] | ||
}; | ||
""")) | ||
print("read: ", await db.query("select * from person")) | ||
|
||
print("update: ", await db.query(""" | ||
update person content { | ||
user: 'you', | ||
pass: 'more_safe', | ||
tags: ['awesome'] | ||
}; | ||
""")) | ||
print("delete: ", await db.query("delete person")) | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio | ||
|
||
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 |
---|---|---|
@@ -1,62 +1,59 @@ | ||
from surrealdb import AsyncSurrealDB | ||
|
||
|
||
async def main(): | ||
"""Example of how to use the SurrealDB client.""" | ||
db = AsyncSurrealDB("ws://localhost:8000/database/namespace") | ||
|
||
await db.connect() | ||
|
||
await db.signin({ | ||
"username": "root", | ||
"password": "root", | ||
}) | ||
|
||
print("Using methods") | ||
print("create: " ,await db.create( | ||
"person", | ||
{ | ||
"user": "me", | ||
"pass": "safe", | ||
"marketing": True, | ||
"tags": ["python", "documentation"], | ||
}, | ||
)) | ||
print("read: ", await db.select("person")) | ||
print("update: ", await db.update("person", { | ||
"user":"you", | ||
"pass":"very_safe", | ||
"marketing": False, | ||
"tags": ["Awesome"] | ||
})) | ||
print("delete: ", await db.delete("person")) | ||
|
||
# You can also use the query method | ||
# doing all of the above and more in SurrealQl | ||
|
||
# In SurrealQL you can do a direct insert | ||
# and the table will be created if it doesn't exist | ||
print("Using justawait db.query") | ||
print("create: ", await db.query(""" | ||
insert into person { | ||
user: 'me', | ||
pass: 'very_safe', | ||
tags: ['python', 'documentation'] | ||
}; | ||
""")) | ||
print("read: ", await db.query("select * from person")) | ||
|
||
print("update: ", await db.query(""" | ||
update person content { | ||
user: 'you', | ||
pass: 'more_safe', | ||
tags: ['awesome'] | ||
}; | ||
""")) | ||
print( "delete: ", await db.query("delete person")) | ||
async with AsyncSurrealDB("ws://localhost:8000") as db: | ||
await db.sign_in("root", "root") | ||
await db.use("test", "test") | ||
|
||
print("Using methods") | ||
print("create: ", await db.create( | ||
"person", | ||
{ | ||
"user": "me", | ||
"pass": "safe", | ||
"marketing": True, | ||
"tags": ["python", "documentation"], | ||
}, | ||
)) | ||
print("read: ", await db.select("person")) | ||
print("update: ", await db.update("person", { | ||
"user": "you", | ||
"pass": "very_safe", | ||
"marketing": False, | ||
"tags": ["Awesome"] | ||
})) | ||
print("delete: ", await db.delete("person")) | ||
|
||
# You can also use the query method | ||
# doing all of the above and more in SurrealQl | ||
|
||
# In SurrealQL you can do a direct insert | ||
# and the table will be created if it doesn't exist | ||
print("Using justawait db.query") | ||
print("create: ", await db.query(""" | ||
insert into person { | ||
user: 'me', | ||
pass: 'very_safe', | ||
tags: ['python', 'documentation'] | ||
}; | ||
""")) | ||
print("read: ", await db.query("select * from person")) | ||
|
||
print("update: ", await db.query(""" | ||
update person content { | ||
user: 'you', | ||
pass: 'more_safe', | ||
tags: ['awesome'] | ||
}; | ||
""")) | ||
print("delete: ", await db.query("delete person")) | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio | ||
|
||
asyncio.run(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
Oops, something went wrong.