Skip to content

Commit

Permalink
Merge pull request #46 from nitrictech/feature/context-api
Browse files Browse the repository at this point in the history
feat: context based faas api
  • Loading branch information
tjholm authored Oct 9, 2021
2 parents cddd871 + fb79c84 commit 6305ebe
Show file tree
Hide file tree
Showing 31 changed files with 1,030 additions and 1,000 deletions.
5 changes: 4 additions & 1 deletion examples/documents/delete.py
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]
5 changes: 4 additions & 1 deletion examples/documents/get.py
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]
5 changes: 4 additions & 1 deletion examples/documents/paged_results.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# [START import]
from nitric.api import Documents

# [END import]
async def documents_paged_results():
# [START snippet]
# [START snippet]
docs = Documents()

query = docs.collection("Customers").query().where("active", "==", True).limit(100)
Expand All @@ -13,4 +14,6 @@ async def documents_paged_results():
# Fetch next page
if results.paging_token:
results = await query.page_from(results.paging_token).fetch()


# [END snippet]
5 changes: 4 additions & 1 deletion examples/documents/query.py
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]
5 changes: 4 additions & 1 deletion examples/documents/query_filter.py
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]
5 changes: 4 additions & 1 deletion examples/documents/query_limits.py
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]
15 changes: 9 additions & 6 deletions examples/documents/refs.py
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]
5 changes: 4 additions & 1 deletion examples/documents/set.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# [START import]
from nitric.api import Documents

# [END import]
async def documents_set():
# [START snippet]
# [START snippet]
docs = Documents()

document = docs.collection("products").doc("nitric")
Expand All @@ -16,4 +17,6 @@ async def documents_set():
}
)
)


# [END snippet]
7 changes: 5 additions & 2 deletions examples/documents/streamed.py
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]
13 changes: 7 additions & 6 deletions examples/documents/sub_col_query.py
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]
5 changes: 4 additions & 1 deletion examples/documents/sub_doc_query.py
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]
5 changes: 4 additions & 1 deletion examples/events/event_ids.py
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]
5 changes: 4 additions & 1 deletion examples/events/publish.py
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]
5 changes: 4 additions & 1 deletion examples/queues/receive.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# [START import]
from nitric.api import Queues, Task

# [END import]
async def queues_receive():
# [START snippet]
# [START snippet]
# Construct a new queue client with default settings
queue = Queues().queue("my-queue")

Expand All @@ -13,4 +14,6 @@ async def queues_receive():

# Complete the task if it was processed successfully
await task.complete()


# [END snippet]
5 changes: 4 additions & 1 deletion examples/queues/send.py
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]
5 changes: 4 additions & 1 deletion examples/secrets/access.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# [START import]
from nitric.api import Secrets

# [END import]
async def secret_access():
# [START snippet]
# [START snippet]
# Construct a new secret client
secrets = Secrets()

Expand All @@ -11,4 +12,6 @@ async def secret_access():
value = await secrets.secret("database.password").version(version).access()

password = value.as_string()


# [END snippet]
5 changes: 4 additions & 1 deletion examples/secrets/latest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# [START import]
from nitric.api import Secrets

# [END import]
async def secret_latest():
# [START snippet]
# [START snippet]
# Construct a new secret client
secrets = Secrets()

Expand All @@ -11,4 +12,6 @@ async def secret_latest():

# Access the latest secret version
value = await latest_version.access()


# [END snippet]
5 changes: 4 additions & 1 deletion examples/secrets/put.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# [START import]
from nitric.api import Secrets

# [END import]
async def secret_put():
# [START snippet]
# [START snippet]
# Construct a new secret client
secrets = Secrets()

Expand All @@ -12,4 +13,6 @@ async def secret_put():

# Access the exact version of the put secret, for future reference
password = await new_version.access()


# [END snippet]
5 changes: 4 additions & 1 deletion examples/storage/delete.py
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]
5 changes: 4 additions & 1 deletion examples/storage/read.py
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]
5 changes: 4 additions & 1 deletion examples/storage/write.py
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]
Loading

0 comments on commit 6305ebe

Please sign in to comment.