Coder Social home page Coder Social logo

fathom's Introduction

[WIP] Fathom - A Neo4j PHP Mapper

Installation

  • Fork the repository and install the dependencies with composer install

Defining your schema

Fathom makes use of the yaml format for schema definition, the readibility of the schema is easy, let's take a look :

#SimpleNode
class: Fathom\Play\SimpleNode
auto_id: ~
fields:
    username:
        type: string
        length: 255
    klout:
        type: integer
        negative: false
    timestamp:
        type: integer
        negative: false

The class keyword is used to define your namespace, the auto_id keyword is set to default, currently it uses a v4 uuid to define the nodes id, this should evolve to multiple and custom id generators.

Building your mapping files

There is a CLI tool available to build your mapping files based on the schema.

bin/fathom generate:mapping

The interactive console will prompt you to enter the path to your schema folder, let's say it is under the src/Acme/Schema folder, you can just enter src/Acme.

Validating Mapping File "SimpleNode.yml"...
Mapping file SimpleNode.yml validated
Validating Mapping File "Flag.yml"...
Mapping file Flag.yml validated
All files validated, starting mapping generation ...

There will be two kinds of files generated, first a Node Entity extending the NodeMapper, the NodeEntity is made for you to add custom logic, the Node Mapper contains generated methods and cannot be modified.

Second, the NodeQuery extending also a generic NodeQuery class, this class is used for querying the database.

The generic files are stored under the src/xxx/GeneratedMapping folder.

Using the mappers

In order to use the mappers, you need a connection to the Neo4j database. This is include currently in this package, however it should be decoupled later

require "vendor/autoload.php";

use Neoxygen\Navdis\Client\Client as NClient;

$conn = new NClient();

You can use the mappers to handle your data :

require "vendor/autoload.php";

use Neoxygen\Navdis\Client\Client as NClient;
use Fathom\Play\SimpleNode;
use Fathom\Play\SimpleNodeQuery;

$conn = new NClient();

// Creating a new SimpleNode instance, setting values and saving to the database

$node = new SimpleNode();
$node->setUsername('john doe');
$node->setKlout(43);
$node->save();

// The generated id is now available:
echo $node->getId();


// Retrieving nodes from the database

$q = new SimpleNodeQuery($conn);
$node = $q->findById("f990d04b-3848-03fc-8772-d000e6276faa");

fathom's People

Contributors

ikwattro avatar

Watchers

James Cloos avatar

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.