Skip to content

Commit c7f1809

Browse files
Merge pull request #45 from Neelterminusdb/patch-1
Added query documents and branch operations for netflix tutorial
2 parents cd77df2 + eb0b3d2 commit c7f1809

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Diff for: netflix/netflix.py

+48
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,44 @@ def read_data(csv):
7171

7272
return records
7373

74+
def query_documents(client):
75+
documents = client.get_all_documents()
76+
77+
# documents comes back as a iterable that can be convert into a list
78+
print("\nAll documents\n")
79+
print(list(documents))
80+
81+
matches = client.query_document({"@type" : "Netflix",
82+
"type_of": "Movie",
83+
"release_year": "2020"})
84+
85+
# matches comes back as a iterable that can be convert into a list
86+
print("\nDocuments matches\n")
87+
print(list(matches))
88+
89+
# If you want to get a specific number of records, just add count=number when calling both functions:
90+
documents = client.get_all_documents(count=5)
91+
matches = client.query_document({"@type" : "Netflix",
92+
"type_of": "Movie",
93+
"release_year": "2020"}, count=5)
94+
95+
def branches(client):
96+
#You can create a new branch by calling the create_branch method
97+
client.create_branch("some_branch", empty=False)
98+
99+
# When empty is set to False, a new branch will be created,
100+
# containing the schema and data inserted into the database previously.
101+
# If set to True, an empty branch will be created.
102+
client.create_branch("some_branch1", empty=True)
103+
104+
# You can delete a branch by calling the delete and passing the name of the branch as parameter.
105+
client.delete_branch("some_branch")
106+
107+
# List all branches
108+
branches = client.get_all_branches()
109+
110+
print(branches)
111+
74112
if __name__ == "__main__":
75113
db_id = "Netflix"
76114
url = "netflix.csv"
@@ -89,3 +127,13 @@ def read_data(csv):
89127
insert_data(client, url)
90128
results = client.get_all_documents(count=10)
91129
print("\nRESULTS\n", list(results))
130+
131+
print("\nQUERYING DOCUMENTS\n")
132+
query_documents(client)
133+
134+
print("\nBranches\n")
135+
branches(client)
136+
137+
# Get the whole commit history:
138+
commit_history = client.get_commit_history()
139+
print("\nCOMMIT HISTORY\n",commit_history)

0 commit comments

Comments
 (0)