Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Version bump. Last Composer update for this package. Install server a…
Browse files Browse the repository at this point in the history
…nd pubsub packages directly to get Nymph 2.
  • Loading branch information
hperrin committed Oct 27, 2017
1 parent 56e5ac9 commit c007b64
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 166 deletions.
130 changes: 3 additions & 127 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,132 +1,8 @@
# Nymph - collaborative app data

[![Build Status](https://img.shields.io/travis/sciactive/nymph-server/master.svg?style=flat)](http://travis-ci.org/sciactive/nymph-server) [![Latest Stable Version](https://img.shields.io/packagist/v/sciactive/nymph.svg?style=flat)](https://packagist.org/packages/sciactive/nymph) [![License](https://img.shields.io/packagist/l/sciactive/nymph.svg?style=flat)](https://packagist.org/packages/sciactive/nymph) [![Open Issues](https://img.shields.io/github/issues/sciactive/nymph.svg?style=flat)](https://github.com/sciactive/nymph/issues)

Nymph is an object data store that is easy to use in JavaScript and PHP.

## Installation

You can install Nymph with Composer for the server side files, and NPM for the client side files.

```sh
composer require sciactive/nymph

npm install --save nymph-client
```

This repository is a container for the [server](https://github.com/sciactive/nymph-server), [pubsub](https://github.com/sciactive/nymph-pubsub), and [client](https://github.com/sciactive/nymph-client) files.

## Demos

Try opening the same one in two windows, and see one window react to changes in the other.

- [Todo](http://nymph-demo.herokuapp.com/examples/todo/svelte/) ([source](https://github.com/sciactive/nymph-examples/tree/master/examples/todo/))
- [Sudoku](http://nymph-demo.herokuapp.com/examples/sudoku/) ([source](https://github.com/sciactive/nymph-examples/tree/master/examples/sudoku))
- [Simple Clicker](http://nymph-demo.herokuapp.com/examples/clicker/) ([source](https://github.com/sciactive/nymph-examples/tree/master/examples/clicker))

## Nymph Query Language vs Just SQL

#### Nymph Query from Frontend

```js
Nymph.getEntities({"class":"BlogPost"}, {"type":"&", "like":["title","%easy%"], "data":["archived",false]}).then(function(entities){
console.log(entities);
}, function(){
alert("Error");
});
```
*No need for a specific endpoint here. Nymph uses the same endpoint for all client side queries.*

#### Equivalent SQL Query from Frontend

```js
$.ajax({
"url": "titlesearch.php",
"data": {"title":"%not as easy%","archived":"false"},
"dataType": "JSON",
"success": function(entities){
console.log(entities);
},
"error": function(){
alert("Error");
}
});
```
```php
<?php
// This file is the endpoint for searching for a BlogPost by title.
$mysqli = new mysqli();

$title = $_GET['title'];
$archived = ($_GET['archived'] == "true" ? 'TRUE' : 'FALSE');
$entities = array();
if ($stmt = $mysqli->prepare("SELECT * FROM BlogPosts WHERE title LIKE '?' AND archived=?")) {
$stmt->bind_param("ss", $title, $archived);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$entities[] = $row;
}
$stmt->close();
}

header("Content-Type: application/json");
echo json_encode($entities);
$mysqli->close();
```
*Without Nymph, every time you want a new type of query available on the frontend, you're going to need to either modify this endpoint or create a new one.*

## What is Nymph?

Nymph takes the objects that hold your data and translates them to relational data to be stored in a SQL database. Nymph has two parts, in both JavaScript and PHP:

<dl>
<dt>Nymph Object</dt>
<dd>The Nymph object is where you communicate with the database and make queries. It also has sorting methods to help you sort arrays of entities.</dd>
<dt>Entity Class</dt>
<dd>The Entity class is what you will extend to make data objects.</dd>
</dl>

Both of these exist in PHP and JavaScript, and interacting with them in either environment is very similar. In JavaScript, since data can't be retrieved immediately, Nymph will return promises instead of actual data.

Nymph in JavaScript handles any database interaction by using a NymphREST endpoint. You can build an endpoint by following the instructions in the [Setup Guide](https://github.com/sciactive/nymph/wiki/Setup-Guide).

## Setting up a Nymph Application

<div dir="rtl">Quick Setup with Composer</div>
This used to be a package for Composer to include both `sciactive/nymph-server` and `sciactive/nymph-pubsub`. As of Nymph version 2.0, this package will no longer be updated. Instead, you should install nymph-server and nymph-pubsub directly.

```sh
composer require sciactive/nymph
composer require sciactive/nymph-server
composer require sciactive/nymph-pubsub
```
```php
require 'vendor/autoload.php';
use Nymph\Nymph;
Nymph::configure([
'MySQL' => [
'host' => 'your_db_host',
'database' => 'your_database',
'user' => 'your_user',
'password' => 'your_password'
]
]);

// You are set up. Now make a class like `MyEntity` and use it.

require 'my_autoloader.php';

$myEntity = new MyEntity();
$myEntity->myVar = "myValue";
$myEntity->save();

$allMyEntities = Nymph::getEntities(['class' => 'MyEntity']);
```

For a thorough step by step guide to setting up Nymph on your own server, visit the [Setup Guide](https://github.com/sciactive/nymph/wiki/Setup-Guide).

## Documentation

Check out the documentation in the wiki, [Technical Documentation Index](https://github.com/sciactive/nymph/wiki/Technical-Documentation).

## What's Next

Up next is an ACL system for Nymph. It will allow you to restrict what entities a user, or group of users, has access to. It will include a user and group entity class. It will soon be available at [tilmeld.org](http://tilmeld.org/).
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "sciactive/nymph",
"description": "Powerful object data storage and querying for collaborative web apps.",
"version": "1.6.0",
"time": "2017-07-21",
"description": "Don't use sciactive/nymph anymore. You should use sciactive/nymph-server and sciactive/nymph-pubsub.",
"version": "1.6.2",
"time": "2017-10-26",
"homepage": "http://nymph.io/",
"type": "library",
"authors": [
Expand Down Expand Up @@ -36,7 +36,7 @@
]
},
"require": {
"sciactive/nymph-server": "1.6.0",
"sciactive/nymph-server": "1.6.2",
"sciactive/nymph-pubsub": "1.6.0"
},
"require-dev": {
Expand Down
70 changes: 35 additions & 35 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c007b64

Please sign in to comment.