npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

orientdb-sugar

v0.1.34

Published

Syntactic sugar for OrientDB using orientjs.

Downloads

53

Readme

OrientDB-Sugar

Provides syntactic sugar, including gremlin-like operators, for Graph database operations on OrientDB.

API documentation

API documentation

Usage

import { Client } from 'orientdb-sugar'

async function main() {

  // Connect to your server
  const client = new Client({
    host: 'localhost',
    port: 2424,
    username: 'leroyjenkins',
    password: 'ohgodhesgoingin',
    manageSchema: true, // <-- Enables automatic creation of classes, properties, and indices.
    log: console.log // <-- Enables you to see what commands and queries are being run.
  })

  const db = client.db('test')

  // Define a schema
  const Actor = db.vertex('Actor')
    .property('name', 'string')
    .index('name', 'unique')

  const ActedIn = db.edge('ActedIn')

  const StarredIn = db.edge('StarredIn')

  const Film = db.vertex('Film')
    .property('name', 'string')
    .property('year', 'integer')
    .index('name', 'unique')

  // Add some data
  // Create a vertex
  const tomHanks = await Actor.upsert({ name: 'Tom Hanks' }, { born: '1956-07-09' })

  // Create another vertex
  const big = await Film.upsert({ name: 'Big' }, { year: 1988, release: '1998-06-03', genre: ['Drama', 'Fantasy'] })

  // Create an edge
  await ActedIn.upsert(tomHanks, big, { character: 'Josh Baskin' })

  // Another way: Learning

  // By reference, "Learn Tom Hanks acted in Big"
  await db.learn(tomHanks, ActedIn, big)
    
  // By anonymous, "Learn actor Jared Rushton acted in film Big as Billy".
  // This method assumes the only property of the first object is the class,
  // and the first property of the inner object is the unique identifier.
  await db.learn(
    { Actor: { name: 'Jared Rushton' }}, // <-- Anonymous vertex upsert
    'ActedIn',                           // <-- Edge name
    { Film: { name: 'Big'}},             // <-- Anonymous vertex upsert
    { character: 'Billy' }               // <-- Edge properties
  )

  // Bulk learning

  // Actors Robert Downey Jr., Chris Evans, Mark Ruffalo, Chris Hemsworth, Scarlett Johansson,
  // acted in Avengers, Avengers: Age of Ultron, Avengers: Infinity War, and Avengers: Endgame

  await db.learn(
    [
      {Actor: { name: 'Robert Downey Jr.'}},
      {Actor: { name: 'Chris Evans' }},
      {Actor: { name: 'Mark Ruffalo' }},
      {Actor: { name: 'Chris Hemsworth' }},
      {Actor: { name: 'Scarlett Johansson' }}
    ],
    [
      {ActedIn: { starring: true }},
      {StarredIn: {}}
    ],
    [
      {Film: { name: 'Avengers', year: 2012 }},
      {Film: { name: 'Avengers: Age of Ultron', year: 2015 }},
      {Film: { name: 'Avengers: Infinity War', year: 2018 }},
      {Film: { name: 'Avengers: Endgame', year: 2019 }}
    ]
  )

  // Get a single record
  const rdj = await Actor.select({name: 'Robert Downey Jr.'}).one()

  // Traverse the graph by reference, and retrieve many records as an array.
  const costars = await Actor.traverse(rdj).out(ActedIn).in(StarredIn).where({name: {$ne: rdj.name}}).toArray()
  console.log(`${rdj.name}'s co-stars are ${costars.map(x => x.name).join(', ')}`)
  console.log('They acted in:')

  // Traverse the graph by anonymous, and stream results using async generator.
  for await (let film of db.v(costars).out('ActedIn')) {
    console.log(film.name)
  }

  // Close the connection
  await client.close()
}