-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from nitrictech/feature/context-api
feat: context based faas api
- Loading branch information
Showing
31 changed files
with
1,030 additions
and
1,000 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_delete(): | ||
# [START snippet] | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
document = docs.collection("products").doc("nitric") | ||
|
||
await document.delete() | ||
|
||
|
||
# [END snippet] |
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,11 +1,14 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_get(): | ||
# [START snippet] | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
document = docs.collection("products").doc("nitric") | ||
|
||
product = await document.get() | ||
|
||
|
||
# [END snippet] |
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_query(): | ||
# [START snippet] | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
query = docs.collection("Customers").query() | ||
|
||
# Execute query | ||
results = await query.fetch() | ||
|
||
|
||
# [END snippet] |
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,11 +1,14 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_query_filter(): | ||
# [START snippet] | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
query = docs.collection("Customers").query().where("country", "==", "US").where("age", ">=", 21) | ||
|
||
results = await query.fetch() | ||
|
||
|
||
# [END snippet] |
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,11 +1,14 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_query_limits(): | ||
# [START snippet] | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
query = docs.collection("Customers").query().limit(1000) | ||
|
||
results = await query.fetch() | ||
|
||
|
||
# [END snippet] |
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,13 +1,16 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
def documents_refs(): | ||
# [START snippet] | ||
docs = Documents() | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
# create a reference to a collection named 'products' | ||
products = docs.collection("products") | ||
|
||
# create a reference to a document with the id 'nitric' | ||
nitric = products.doc("nitric") | ||
|
||
# create a reference to a collection named 'products' | ||
products = docs.collection("products") | ||
|
||
# create a reference to a document with the id 'nitric' | ||
nitric = products.doc("nitric") | ||
# [END snippet] |
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_streamed(): | ||
# [START snippet] | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
query = docs.collection("Customers").query() | ||
|
||
async for doc in query.stream(): | ||
# Process doc stream... | ||
print(doc.content) | ||
# [END snippet] | ||
|
||
|
||
# [END snippet] |
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,13 +1,14 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_sub_col_query(): | ||
# [START snippet] | ||
docs = Documents() | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
query = docs.collection("Customers").collection("Orders").query() | ||
|
||
results = await query.fetch() | ||
|
||
query = (docs.collection("Customers") | ||
.collection("Orders") | ||
.query()) | ||
|
||
results = await query.fetch() | ||
# [END snippet] |
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,11 +1,14 @@ | ||
# [START import] | ||
from nitric.api import Documents | ||
|
||
# [END import] | ||
async def documents_sub_doc_query(): | ||
# [START snippet] | ||
# [START snippet] | ||
docs = Documents() | ||
|
||
query = docs.collection("Customers").doc("apple").collection("Orders").query() | ||
|
||
results = await query.fetch() | ||
|
||
|
||
# [END snippet] |
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,13 +1,16 @@ | ||
# [START import] | ||
from nitric.api import Events, Event | ||
|
||
# [END import] | ||
async def events_event_ids(): | ||
# [START snippet] | ||
# [START snippet] | ||
# Create a new Event Client with default settings | ||
topic = Events().topic("my-topic") | ||
|
||
payload = {"content": "of event"} | ||
|
||
# Publish an event to the topic 'my-topic' | ||
event = await topic.publish(Event(payload=payload)) | ||
|
||
|
||
# [END snippet] |
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,13 +1,16 @@ | ||
# [START import] | ||
from nitric.api import Events, Event | ||
|
||
# [END import] | ||
async def events_publish(): | ||
# [START snippet] | ||
# [START snippet] | ||
# Create a new Event Client with default settings | ||
topic = Events().topic("my-topic") | ||
|
||
payload = {"content": "of event"} | ||
|
||
# Publish an event to the topic 'my-topic' | ||
event = await topic.publish(Event(payload=payload)) | ||
|
||
|
||
# [END snippet] |
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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
# [START import] | ||
from nitric.api import Queues, Task | ||
|
||
# [END import] | ||
async def queues_send(): | ||
# [START snippet] | ||
# [START snippet] | ||
# Construct a new queue client with default settings | ||
queues = Queues() | ||
|
||
payload = {"content": "of task"} | ||
|
||
# Publish a task to a queue | ||
await queues.queue("my-queue").send(Task(payload=payload)) | ||
|
||
|
||
# [END snippet] |
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
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
# [START import] | ||
from nitric.api import Storage | ||
|
||
# [END import] | ||
async def storage_delete(): | ||
# [START snippet] | ||
# [START snippet] | ||
# Construct a new storage client with default settings | ||
storage = Storage() | ||
|
||
# Delete the file | ||
await storage.bucket("my-bucket").file("path/to/item").delete() | ||
|
||
|
||
# [END snippet] |
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,13 +1,16 @@ | ||
# [START import] | ||
from nitric.api import Storage | ||
|
||
# [END import] | ||
async def storage_read(): | ||
# [START snippet] | ||
# [START snippet] | ||
# Construct a new storage client with default settings | ||
storage = Storage() | ||
|
||
file_ref = storage.bucket("my-bucket").file("path/to/item") | ||
|
||
# Read bytes from the file | ||
file = await file_ref.read() | ||
|
||
|
||
# [END snippet] |
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,13 +1,16 @@ | ||
# [START import] | ||
from nitric.api import Storage | ||
|
||
# [END import] | ||
async def storage_write(): | ||
# [START snippet] | ||
# [START snippet] | ||
# Construct a new storage client with default settings | ||
storage = Storage() | ||
|
||
file_ref = storage.bucket("my-bucket").file("path/to/item") | ||
|
||
# Write bytes to the file | ||
await file_ref.write(b"example content") | ||
|
||
|
||
# [END snippet] |
Oops, something went wrong.