def create_client_stub(self): self.client_stub = pydgraph.DgraphClientStub('localhost:9080')
from function import handler # get params MINIO_URL = os.getenv('MINIO_URL') MINIO_ACCESS = os.getenv('MINIO_ACCESS_KEY') MINIO_SECRET = os.getenv('MINIO_SECRET_KEY') DB_URL= os.getenv('DB_URL') app = Flask(__name__) # create minio client client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=False) # db client db_stub = pydgraph.DgraphClientStub(DB_URL) db = pydgraph.DgraphClient(db_stub) @app.route('/', methods=['POST', 'HEAD']) def call_handler(): if request.method == 'HEAD': return ('', 200) try: handler.handle(client, db, request.get_data()) return ('', 200) except Exception: return ('', 500) if __name__ == '__main__': serve(app, host='0.0.0.0', port=8009)
def create_client(addr=SERVER_ADDR): return pydgraph.DgraphClient(pydgraph.DgraphClientStub(addr))
import pydgraph import json server = "10.0.128.111:9080" client_stub = pydgraph.DgraphClientStub(server) client = pydgraph.DgraphClient(client_stub) email = "*****@*****.**" # Run query. query = "query all($a: string){ get_uid(func: eq(email, $a )) { uid } }" variables = {'$a': email} res = client.query(query, variables=variables) # res = client.query(query) resp_json = json.loads(res.json); print(resp_json) if len(resp_json["get_uid"]) == 0: print("Entry doesnt exist") # Adding it to dgraph # https://docs.dgraph.io/mutations/#json-mutation-format data = { "name": email.split("@")[0], "email": email} txn = client.txn() txn.mutate(set_obj=data) txn.commit()
import csv import json import logging import os import click import pydgraph from pprint import pprint # In[2]: logger = logging.getLogger("Dependency Graph Generation") logger.setLevel(logging.DEBUG) client_stub = pydgraph.DgraphClientStub('localhost:9080') client = pydgraph.DgraphClient(client_stub) # In[29]: # Drop All - discard all data and start from a clean slate. def drop_all(client): return client.alter(pydgraph.Operation(drop_all=True)) # Set schema. def set_schema(client): schema = """ name: string @index(exact) . depends: [uid] @reverse .
def main(queryStatement, host, queryName): client_stub = pydgraph.DgraphClientStub(host) client = pydgraph.DgraphClient(client_stub) result = query_data(client, queryStatement, queryName) client_stub.close() return result
def create_client_stub(): return pydgraph.DgraphClientStub('localhost:9080')
print(schema.get_schema()) op = pydgraph.Operation(schema=schema.get_schema()) client.alter(op) def clear_dgraph(client): op = pydgraph.Operation(drop_all=True) client.alter(op) if __name__ == '__main__': setup_dotenv() DGRAPTH_ENDPOINT = os.environ.get("DGRAPTH_ENDPOINT") print('connect dgraph: ', DGRAPTH_ENDPOINT) client_stub = pydgraph.DgraphClientStub(DGRAPTH_ENDPOINT) client = pydgraph.DgraphClient(client_stub) clear_dgraph(client) setup_dgraph(client) SQLITE_DB = os.environ.get("DB_PATH") print('read sqlite db: ', SQLITE_DB) con = sqlite3.connect(SQLITE_DB) cur = con.cursor() oid_to_uid = {} try: # insert objects print('insert objects') for row in cur.execute(sql.OBJECTS_SQL):
def __init__(self): self.seen = {} client_stub = dg.DgraphClientStub("localhost:9080") self.client = dg.DgraphClient(client_stub)
import pydgraph client_stub = pydgraph.DgraphClientStub( 'https://shaky-vacation.us-west-2.aws.cloud.dgraph.io/graphql') client = pydgraph.DgraphClient(client_stub) schema = 'name: string @index(exact) .' op = pydgraph.Operation(schema=schema) client.alter(op)
import pydgraph import datetime d = datetime.datetime(1980, 1, 1, 23, 0, 0, 0).isoformat() print(type(d), d) client_stub = pydgraph.DgraphClientStub('192.168.1.44:9080') client = pydgraph.DgraphClient(client_stub) print(client) op = pydgraph.Operation(drop_all=True) action = client.alter(op) print(action) # p = { # "set": [ # { # "uid": "_:company1", # "industry": "Machinery", # "name": "CompanyABC" # }, # { # "uid": "_:company2", # "industry": "High Tech", # "name": "The other company" # }, # { # "uid": "_:jack", # "works_for": { "uid": "_:company1"}, # "name": "Jack" # }, # {
def create_client(addr=SERVER_ADDR): """Creates a new client object using the given address.""" return pydgraph.DgraphClient(pydgraph.DgraphClientStub(addr))
def newDgraphClient(): client_stub = pydgraph.DgraphClientStub('host.docker.internal:9080') return pydgraph.DgraphClient(client_stub)
def __init__(self): dgraph_source = 'dgraph.mosaics.ai' self.client_stub = pydgraph.DgraphClientStub(dgraph_source) self.client = pydgraph.DgraphClient(self.client_stub) print("")