Giter VIP home page Giter VIP logo

Neo4-js

Build Status dependencies Status devDependencies Status styled with prettier

Neo4-js is a object-graph mapper for JavaScript and neo4j with full TypeScript support. Neo4-js hides repetitive queries such as the basic CRUD operations to the developer. For best development experience use TypeScript to obtain good autocomplete results.

Usage

With neo4-js you are able to quickly define your data model but maintain complete control over your models. The following code snipped shows how you can work with neo4-js.

type PersonProps = {
  name?: StringProperty;
};

type TaskProps = {
  title?: StringProperty;
  done?: boolean;
};

class PersonModel extends Model<PersonProps, PersonInstance> {}
const Person: PersonModel = new PersonModel("Person");

class TaskModel extends Model<TaskProps, TaskInstance> {}
const Task: TaskModel = new TaskModel("Task");

const TaskCreatorRelation = relation
  .from(() => Person)
  .to(() => Task)
  .via("created");

const TaskAssigneeRelation = relation
  .from(Person)
  .to(Task)
  .via("assigned");

@model(Person)
class PersonInstance extends ModelInstance<PersonProps> {
  @hasMany(Task, TaskCreatorRelation)
  tasks: HasManyActions<TaskProps, TaskInstance>;

  @hasMany(Task, TaskAssigneeRelation)
  assignedTasks: HasManyActions<TaskProps, TaskInstance>;
}

@model(Task)
class TaskInstance extends ModelInstance<TaskProps> {
  @hasOne(() => Person, () => TaskCreatorRelation)
  creator: HasOneActions<PersonProps, PersonInstance>;
}

(async () => {
  const paul: PersonInstance = await Person.create({ name: "Paul" });

  const propsArray: TaskProps[] = [
    {
      title: "Buy milk",
    },
    {
      title: "Buy beer",
      done: false,
    },
  ];

  const tasks: TaskInstance[] = await paul.tasks.create(propsArray);
})();

Documentation

The documentation is not completed yet but you'll find the basics on neo4.js.org. Any help is very much appreciated!

Installing

To use neo4-js properly you need to add TypeScript to your project. For now we also install ts-node so that we are able to run our code without compiling it manually before running.

yarn add -D typescript ts-node

I recommend using the following tsconfig.json configuration.

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "ES6",
    "experimentalDecorators": true,
  }
}

You might also install Docker to quickly create a neo4j database without any further installations. For neo4-js I used the following bash script to start a neo4j instance in docker. To run it you might create a scripts directory and add the following to neo4j-startup.sh, make sure you can execute the script with chmod 777 neo4j-startup.sh (because why not 777 on my local machine :P).

# REST PORT: 10000
# BOLT PORT: 10001
echo "docker run -p 10000:7474 -p 10001:7687 --rm --env=NEO4J_AUTH=none neo4j"
docker run -p 10000:7474 -p 10001:7687 --rm --env=NEO4J_AUTH=none neo4j

The only runtime dependency you need to start using neo4-js is neo4-js itself.

yarn add neo4-js

Built With

  • TypeScript - TypeScript is a typed superset of Javascript that compiles to plain Javascript.

Contributing

Feel free to send a pull request or create an issue for bugs or feature requests.

Authors

  • Jan Schlacher - Initial work

License

This project is licensed under the MIT License - see the LICENSE.md file for details

neo4-js's Projects

neo4-js doesnโ€™t have any public repositories yet.

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.