Giter VIP home page Giter VIP logo

psgremlin's Introduction

PSGremlin

Powershell wrapper for executing gremlin queries using Gremlin.Net

PSGremlin Logo

Using PSGremlin to connect to Cosmos DB

Sample adapted from https://github.com/Azure-Samples/azure-cosmos-db-graph-gremlindotnet-getting-started

# replace variables with values of your own
$hostname = "your-endpoint.gremlin.cosmosdb.azure.com"
$authKey = ConvertTo-SecureString -AsPlainText -Force -String 'your-key'
$database = "your-database"
$collection = "your-collection-or-graph"

$gremlinParams = @{
    Hostname = $hostname
    Credential = New-Object System.Management.Automation.PSCredential "/dbs/$database/colls/$collection", $authKey
}

$queries = [ordered]@{
    Cleanup       = "g.V().drop()"
    AddVertex1    = "g.addV('person').property('id', 'thomas').property('firstName', 'Thomas').property('age', 44)"
    AddVertex2    = "g.addV('person').property('id', 'mary').property('firstName', 'Mary').property('lastName', 'Andersen').property('age', 39)"
    AddVertex3    = "g.addV('person').property('id', 'ben').property('firstName', 'Ben').property('lastName', 'Miller')"
    AddVertex4    = "g.addV('person').property('id', 'robin').property('firstName', 'Robin').property('lastName', 'Wakefield')"
    AddEdge1      = "g.V('thomas').addE('knows').to(g.V('mary'))"
    AddEdge2      = "g.V('thomas').addE('knows').to(g.V('ben'))"
    AddEdge3      = "g.V('ben').addE('knows').to(g.V('robin'))"
    UpdateVertex  = "g.V('thomas').property('age', 44)"
    CountVertices = "g.V().count()"
    FilterRange   = "g.V().hasLabel('person').has('age', gt(40))"
    Project       = "g.V().hasLabel('person').values('firstName')"
    Sort          = "g.V().hasLabel('person').order().by('firstName', decr)"
    Traverse      = "g.V('thomas').out('knows').hasLabel('person')"
    Traverse2x    = "g.V('thomas').out('knows').hasLabel('person').out('knows').hasLabel('person')"
    Loop          = "g.V('thomas').repeat(out()).until(has('id', 'robin')).path()"
    DropEdge      = "g.V('thomas').outE('knows').where(inV().has('id', 'mary')).drop()"
    CountEdges    = "g.E().count()"
    DropVertex    = "g.V('thomas').drop()"
}

$queries.Keys | ForEach-Object { 
    Write-Warning -Message "Executing $_"
    $queries[$_] | Invoke-Gremlin @gremlinParams | ConvertTo-Json -Depth 10
} 

Output

WARNING: Executing Cleanup
WARNING: Executing AddVertex1
{
  "id": "thomas",
  "label": "person",
  "type": "vertex",
  "properties": {
    "firstName": [
      {
        "id": "7e0eb8dc-1cb3-4546-b305-b8d0ac1f7578",
        "value": "Thomas"
      }
    ],
    "age": [
      {
        "id": "f5cc0b22-064f-4be5-844e-a0c2f67e808f",
        "value": 44
      }
    ]
  }
}
WARNING: Executing AddVertex2
{
  "id": "mary",
  "label": "person",
  "type": "vertex",
  "properties": {
    "firstName": [
      {
        "id": "334d5421-5584-48e1-aff2-aea6fbb76713",
        "value": "Mary"
      }
    ],
    "lastName": [
      {
        "id": "75b3f500-f10b-4105-acda-89582db1cb67",
        "value": "Andersen"
      }
    ],
    "age": [
      {
        "id": "fc5634f8-0558-4a27-a908-dc1f54bdfc50",
        "value": 39
      }
    ]
  }
}
WARNING: Executing AddVertex3
{
  "id": "ben",
  "label": "person",
  "type": "vertex",
  "properties": {
    "firstName": [
      {
        "id": "f305f929-424b-4c1e-941b-2cc1397804b9",
        "value": "Ben"
      }
    ],
    "lastName": [
      {
        "id": "47f5ed53-d048-456c-9cf5-dcbd8a839ad0",
        "value": "Miller"
      }
    ]
  }
}
WARNING: Executing AddVertex4
{
  "id": "robin",
  "label": "person",
  "type": "vertex",
  "properties": {
    "firstName": [
      {
        "id": "c483ba3b-88d3-49b5-8224-fa06b82fac6e",
        "value": "Robin"
      }
    ],
    "lastName": [
      {
        "id": "61173e84-0b5c-45a4-b263-508296d387c2",
        "value": "Wakefield"
      }
    ]
  }
}
WARNING: Executing AddEdge1
{
  "id": "d41cf40a-fb2e-4b5e-bbde-768dd2292cfc",
  "label": "knows",
  "type": "edge",
  "inVLabel": "person",
  "outVLabel": "person",
  "inV": "mary",
  "outV": "thomas"
}
WARNING: Executing AddEdge2
{
  "id": "be6e9971-9cdf-4825-8875-a30d6c4e70d2",
  "label": "knows",
  "type": "edge",
  "inVLabel": "person",
  "outVLabel": "person",
  "inV": "ben",
  "outV": "thomas"
}
WARNING: Executing AddEdge3
{
  "id": "df4a02a9-b8fb-4bf3-ab75-94862da06f97",
  "label": "knows",
  "type": "edge",
  "inVLabel": "person",
  "outVLabel": "person",
  "inV": "robin",
  "outV": "ben"
}
WARNING: Executing UpdateVertex
{
  "id": "thomas",
  "label": "person",
  "type": "vertex",
  "properties": {
    "firstName": [
      {
        "id": "7e0eb8dc-1cb3-4546-b305-b8d0ac1f7578",
        "value": "Thomas"
      }
    ],
    "age": [
      {
        "id": "985e2d02-85f3-4a71-bf6d-c472d6226dca",
        "value": 44
      }
    ]
  }
}
WARNING: Executing CountVertices
4
WARNING: Executing FilterRange
{
  "id": "thomas",
  "label": "person",
  "type": "vertex",
  "properties": {
    "firstName": [
      {
        "id": "7e0eb8dc-1cb3-4546-b305-b8d0ac1f7578",
        "value": "Thomas"
      }
    ],
    "age": [
      {
        "id": "985e2d02-85f3-4a71-bf6d-c472d6226dca",
        "value": 44
      }
    ]
  }
}
WARNING: Executing Project
[
  "Thomas",
  "Mary",
  "Ben",
  "Robin"
]
WARNING: Executing Sort
[
  {
    "id": "thomas",
    "label": "person",
    "type": "vertex",
    "properties": {
      "firstName": [
        {
          "id": "7e0eb8dc-1cb3-4546-b305-b8d0ac1f7578",
          "value": "Thomas"
        }
      ],
      "age": [
        {
          "id": "985e2d02-85f3-4a71-bf6d-c472d6226dca",
          "value": 44
        }
      ]
    }
  },
  {
    "id": "robin",
    "label": "person",
    "type": "vertex",
    "properties": {
      "firstName": [
        {
          "id": "c483ba3b-88d3-49b5-8224-fa06b82fac6e",
          "value": "Robin"
        }
      ],
      "lastName": [
        {
          "id": "61173e84-0b5c-45a4-b263-508296d387c2",
          "value": "Wakefield"
        }
      ]
    }
  },
  {
    "id": "mary",
    "label": "person",
    "type": "vertex",
    "properties": {
      "firstName": [
        {
          "id": "334d5421-5584-48e1-aff2-aea6fbb76713",
          "value": "Mary"
        }
      ],
      "lastName": [
        {
          "id": "75b3f500-f10b-4105-acda-89582db1cb67",
          "value": "Andersen"
        }
      ],
      "age": [
        {
          "id": "fc5634f8-0558-4a27-a908-dc1f54bdfc50",
          "value": 39
        }
      ]
    }
  },
  {
    "id": "ben",
    "label": "person",
    "type": "vertex",
    "properties": {
      "firstName": [
        {
          "id": "f305f929-424b-4c1e-941b-2cc1397804b9",
          "value": "Ben"
        }
      ],
      "lastName": [
        {
          "id": "47f5ed53-d048-456c-9cf5-dcbd8a839ad0",
          "value": "Miller"
        }
      ]
    }
  }
]
WARNING: Executing Traverse
[
  {
    "id": "mary",
    "label": "person",
    "type": "vertex",
    "properties": {
      "firstName": [
        {
          "id": "334d5421-5584-48e1-aff2-aea6fbb76713",
          "value": "Mary"
        }
      ],
      "lastName": [
        {
          "id": "75b3f500-f10b-4105-acda-89582db1cb67",
          "value": "Andersen"
        }
      ],
      "age": [
        {
          "id": "fc5634f8-0558-4a27-a908-dc1f54bdfc50",
          "value": 39
        }
      ]
    }
  },
  {
    "id": "ben",
    "label": "person",
    "type": "vertex",
    "properties": {
      "firstName": [
        {
          "id": "f305f929-424b-4c1e-941b-2cc1397804b9",
          "value": "Ben"
        }
      ],
      "lastName": [
        {
          "id": "47f5ed53-d048-456c-9cf5-dcbd8a839ad0",
          "value": "Miller"
        }
      ]
    }
  }
]
WARNING: Executing Traverse2x
{
  "id": "robin",
  "label": "person",
  "type": "vertex",
  "properties": {
    "firstName": [
      {
        "id": "c483ba3b-88d3-49b5-8224-fa06b82fac6e",
        "value": "Robin"
      }
    ],
    "lastName": [
      {
        "id": "61173e84-0b5c-45a4-b263-508296d387c2",
        "value": "Wakefield"
      }
    ]
  }
}
WARNING: Executing Loop
{
  "labels": [
    [],
    [],
    []
  ],
  "objects": [
    {
      "id": "thomas",
      "label": "person",
      "type": "vertex",
      "properties": {
        "firstName": [
          {
            "id": "7e0eb8dc-1cb3-4546-b305-b8d0ac1f7578",
            "value": "Thomas"
          }
        ],
        "age": [
          {
            "id": "985e2d02-85f3-4a71-bf6d-c472d6226dca",
            "value": 44
          }
        ]
      }
    },
    {
      "id": "ben",
      "label": "person",
      "type": "vertex",
      "properties": {
        "firstName": [
          {
            "id": "f305f929-424b-4c1e-941b-2cc1397804b9",
            "value": "Ben"
          }
        ],
        "lastName": [
          {
            "id": "47f5ed53-d048-456c-9cf5-dcbd8a839ad0",
            "value": "Miller"
          }
        ]
      }
    },
    {
      "id": "robin",
      "label": "person",
      "type": "vertex",
      "properties": {
        "firstName": [
          {
            "id": "c483ba3b-88d3-49b5-8224-fa06b82fac6e",
            "value": "Robin"
          }
        ],
        "lastName": [
          {
            "id": "61173e84-0b5c-45a4-b263-508296d387c2",
            "value": "Wakefield"
          }
        ]
      }
    }
  ]
}
WARNING: Executing DropEdge
WARNING: Executing CountEdges
2
WARNING: Executing DropVertex

psgremlin's People

Contributors

dependabot-preview[bot] avatar jasonchester avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

larsalmen

psgremlin's Issues

Facing error when executing queries

Imported the PSGremlin module and then ran sample queries, facing following error:
Invoke-Gremlin : Could not load file or assembly 'Gremlin.Net, Version=3.3.0.0, Culture=neutral,
PublicKeyToken=d2035e9aa387a711' or one of its dependencies. The system cannot find the file specified.
...

  • $queries[$_] | Invoke-Gremlin @gremlinParams | ConvertTo-Json -De ...
    
  •                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Invoke-Gremlin], FileNotFoundException
    • FullyQualifiedErrorId : System.IO.FileNotFoundException,PSGremlin.InvokeGremlin

Dependabot couldn't find a <anything>.(cs|vb|fs)proj for this project

Dependabot couldn't find a .(cs|vb|fs)proj for this project.

Dependabot requires a .(cs|vb|fs)proj to evaluate your project's current .NET dependencies. It had expected to find one at the path: /<anything>.(cs|vb|fs)proj.

If this isn't a .NET project, or if it is a library, you may wish to disable updates for it from within Dependabot.

You can mention @dependabot in the comments below to contact the Dependabot team.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.