Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ravendb/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbh committed Jan 31, 2018
2 parents 8b5f3be + 02173a7 commit c2d29e4
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 15 deletions.
5 changes: 0 additions & 5 deletions Documentation/3.5/Samples/python/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Before proceeding to the examples we would like to point out that most of the ar
{CODE-TAB:csharp:C# client_1@Start/GettingStarted.cs /}
{CODE-TAB:java:Java client_1@Start\GettingStarted.java /}
{CODE-TAB:nodejs:Node.js client_1@start\gettingStarted.js /}
{CODE-TAB:python:Python client_1@start\getting_started.py /}
{CODE-TABS/}

{INFO:Singleton}
Expand Down Expand Up @@ -184,15 +185,7 @@ RavenDB is a Document Database, which means that all stored objects are called `
{CODE-TAB:csharp:C# client_2@Start/GettingStarted.cs /}
{CODE-TAB:java:Java client_2@Start\GettingStarted.java /}
{CODE-TAB:nodejs:Node.js client_2@start\gettingStarted.js /}
{CODE-TAB-BLOCK:python:Python}
...
{CODE-TAB-BLOCK/}
{CODE-TAB-BLOCK:ruby:Ruby}
...
{CODE-TAB-BLOCK/}
{CODE-TAB-BLOCK:go:Go}
...
{CODE-TAB-BLOCK/}
{CODE-TAB:python:Python client_2@start\getting_started.py /}
{CODE-TABS/}

### Example II - Loading
Expand All @@ -205,6 +198,7 @@ Beside that Session implements `Unit of Work` pattern, meaning that all **change
{CODE-TAB:csharp:C# client_3@Start/GettingStarted.cs /}
{CODE-TAB:java:Java client_3@Start\GettingStarted.java /}
{CODE-TAB:nodejs:Node.js client_3@start\gettingStarted.js /}
{CODE-TAB:python:Python client_3@start\getting_started.py /}
{CODE-TABS/}

### Example III - Querying
Expand All @@ -219,6 +213,7 @@ Underneath all of the clients are translating the query to the Raven Query Langu
{CODE-TAB:csharp:C# client_4@Start/GettingStarted.cs /}
{CODE-TAB:java:Java client_4@Start\GettingStarted.java /}
{CODE-TAB:nodejs:Node.js client_4@start\gettingStarted.js /}
{CODE-TAB:python:Python client_4@start\getting_started.py /}
{CODE-TAB-BLOCK:sql:RQL}
from Products
where UnitsInStock > 5
Expand Down
Empty file.
78 changes: 78 additions & 0 deletions Documentation/4.0/Samples/python/start/getting_started.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
class Category(object):
def __init__(self,name):
self.Name = name
self.Id = None

class Product(object):
def __init__(self,name, category_id, units_in_stock):
self.Name = name
self.Category = category_id
self.UnitsInStock = units_in_stock
self.Id = None

# region client_1
from pyravendb.store import document_store

with document_store.DocumentStore(
urls=["http://live-test.ravendb.net"], # URL to the Server
# or list of URLs
# to all Cluster Servers (Nodes)

database="Northwind") as store: # Default database that DocumentStore will interact with

conventions = store.conventions # DocumentStore customizations

store.initialize() # Each DocumentStore needs to be initialized before use.
# This process establishes the connection with the Server
# and downloads various configurations
# e.g. cluster topology or client configuration
# endregion

# region client_2
with store.open_session() as session: # Open a session for a default 'Database'
category = Category("Database Category")

session.store(category) # Assign an 'Id' and collection (Categories)
# and start tracking an entity

product = Product(
"RavenDB Database",
category.Id,
10)

session.store(product) # Assign an 'Id' and collection (Products)
# and start tracking an entity

session.save_changes() # Send to the Server
# one request processed in one transaction
# endregion

# region client_3
with store.open_session() as session: # Open a session for a default 'Database'

product = session
.include("Category") # Include Category
.load(product_id, object_type=Product) # Load the Product and start tracking

category = session.load( # No remote calls,
product.Category, # Session contains this entity from .include
object_type=Category)

product.Name = "RavenDB" # Apply changes
category.Name = "Database"

session.save_changes() # Synchronize with the Server
# one request processed in one transaction
# endregion

# region client_4
with store.open_session() as session: # Open a session for a default 'Database'

productNames = list( # Materialize query
session
.query(object_type=Product) # Query for Products
.where_greater_than("UnitsInStock", 5) # Filter
.skip(0).take(10) # Page
.select("Name") # Project
)
# endregion
2 changes: 1 addition & 1 deletion Raven.Documentation.Parser/ParserOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public string GetPathToCodeDirectory(Language language, string documentationVers
case Language.Java:
return Path.Combine(PathToDocumentationDirectory, documentationVersion, "Samples", "java", "src", "test", "java", "net", "ravendb");
case Language.Python:
return Path.Combine(PathToDocumentationDirectory, documentationVersion, "Samples", "python", "ravendb");
return Path.Combine(PathToDocumentationDirectory, documentationVersion, "Samples", "python");
case Language.NodeJs:
return Path.Combine(PathToDocumentationDirectory, documentationVersion, "Samples", "nodejs");
default:
Expand Down

0 comments on commit c2d29e4

Please sign in to comment.