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

tramway-connection-arangodb

v1.3.0

Published

A Provider that permits a Tramway application to connect to an ArangoDB database

Downloads

5

Readme

Tramway ArangoProvider is a simple Provider add-on to simplify the process of implementing calls to arangodb databases and provides an async/await wrapper on the arangojs module.

Installation:

  1. npm install tramway-connection-arangodb --save

Example project

https://gitlab.com/tramwayjs/tramway-connection-example

Documentation

Recommended Folder Structure in addition to Tramway

  • config
  • providers
  • repositories
  • entities

ArangoProvider

The ArangoProvider is a derived Provider which follows the same interface.

Configuration parameters

| Parameter | Default | Usage | | --- | --- | --- | | host | localhost | The host of your arangodb database | | username | | The username for the database | | password | | The password for the database | | database | | The name of the default database to connect to | | port | | The port for the database |

Getting started

Add the following to the imports and exports of the global parameters /config/parameters/global/index.js

import { config as arangoConfig } from 'tramway-connection-arangodb';
export default {
    ...arangoConfig.parameters,
}

Add the following to the imports and exports of the services parameters /config/services/index.js

import { config as arangoConfig } from 'tramway-connection-arangodb';

export default {
    ...arangoConfig.arangoServices,
};

Ensure the following environment variables are configured with the proper credentials:

ARANGO_PORT=8529
ARANGO_USERNAME=username
ARANGO_ROOT_PASSWORD=password
ARANGO_HOST=hostname
ARANGO_DATABASE=database

Exposed Methods with this Library

Provider

Note, the extended ArangoProvider expects an additional parameter collectionName on most methods. Using the ArangoRepository handles this for you. In addition, bulk inserts are possible.

| Function | Availability | | ----- | ----- | | async getOne(id: any, collectionName: string) | Available | | async getMany(ids: any[], collectionName: string) | Available | | async get(collectionName: string) | Available | | async find(conditions: string/Object, collectionName: string) | Available | | async has(id: any, collectionName: string) | Available | | async hasThese(ids : any[], collectionName: string) | Available | | async count(conditions: any, collectionName: string) | Available | | async create(item: Entity/Object, collectionName: string) | Available | | async createMany(item: Entity/Object[], collectionName: string) | Additional, creates a transaction for bulk inserts | | async update(id: any, item: Entity/Object, collectionName: string) | Available | | async replace(id: any, item: Entity/Object, collectionName: string) | Additional | | async updateMany(item: Entity/Object[], collectionName: string) | Additional, creates a transaction for bulk updates | | async delete(id: any, collectionName: string) | Available | | async deleteMany(ids : any[], collectionName: string) | Available | | async query(query: string/Object, values: Object) | Available | | async setup(params: Object) | Available | | async createCollection(collection: string, type: string) | Available | | async createGraph(graphName: string, properties: Object) | Additional | | async createIndex(collectionName: string, fields: string[], type: string, opts: Object) | Additional | | useDatabase(database: string) | Additional |

Collection Types

The following collection types are supported when creating a new Collection:

| Name | Enum value | | --- | --- | | Document (Default) | ArangoProvider.COLLECTION_TYPE_DOCUMENT | | Edge | ArangoProvider.COLLECTION_TYPE_EDGE | | Graph Edge | ArangoProvider.COLLECTION_GRAPH_TYPE_EDGE | | Graph Vertex | ArangoProvider.COLLECTION_TYPE_GRAPH_VERTEX |

Creating collections for graphs will require an additional step in their creation to avoid creating a new set of CRUD methods, or adding additional options to the existing and consistent interface. The provider contains its own resolvers to map collections to types and collections to graphs.

Creating a regular collection can be done in a repository setup method as follows:

    try {
        info = await this.provider.createCollection(this.collection, ArangoProvider.COLLECTION_TYPE_EDGE);
    } catch(e) {
        throw e;
    }

Creating a graph collection will require an additional step to register the collection graph.

    try {
        info = await this.provider.createCollection(this.collection, ArangoProvider.COLLECTION_TYPE_GRAPH_VERTEX);
        this.registerCollectionGraph(this.collection, graphName)
    } catch(e) {
        throw e;
    }

Index Types

The following index types are supported when creating a new Collection:

| Name | Enum value | | --- | --- | | General (Default) | ArangoProvider.INDEX_TYPE_GENERAL | | Hash | ArangoProvider.INDEX_TYPE_HASH | | Skip List | ArangoProvider.INDEX_TYPE_SKIPLIST | | Geo | ArangoProvider.INDEX_TYPE_GEO | | Full Text | ArangoProvider.INDEX_TYPE_TEXT | | Persistent | ArangoProvider.INDEX_TYPE_PERSISTENT | | TTL | ArangoProvider.INDEX_TYPE_TTL |

Creating an index in a repository setup method can be done as follows:

    try {
        info = await this.provider.createIndex(this.collection, ['field1'], ArangoProvider.INDEX_TYPE_HASH, {unique: true, sparse: false});
    } catch(e) {
        throw e;
    }

Creating a Graph

Creating a graph in a repository setup method can be done as follows:

    try {
        info = await this.provider.createGraph(graphName, {
            edgeDefinitions: [
                {
                    collection: 'edges',
                    from: ['start-vertices'],
                    to: ['end-vertices']
                },
            ]
        });
    } catch(e) {
        throw e;
    }

The graph properties uses the same interface as specified in the ArangoDB JS Driver docs.

Repository

| Function | Usability | | --- | --- | | async exists(id: any) | Usable | | async getOne(id: any) | Usable | | async get() | Usable | | async create(entity: Entity) | Usable | | async createMany(entities: Entity[]) | Additional | | async update(entity: Entity) | Usable | | async replace(entity: Entity) | Additional | | async updateMany(entities: Entity[]) | Additional | | async delete(id: any) | Usable | | async find(condtions: string/Object) | Usable | | async getMany(ids: any[]) | Usable | | async count(conditions) | Usable | | async setup() | Usable |