sciactive/nymph

为协作网络应用提供强大的对象数据存储和查询。

1.6.2 2017-10-26 00:00 UTC

README

Nymph

Build Status Demo App Uptime Last Commit license

为协作网络应用提供强大的对象数据存储和查询。

Nymph 是一个拥有强大查询语言、现代客户端库、REST 和发布/订阅服务器以及用户/组管理的 ORM。

弃用通知

Nymph/Tilmeld 的 PHP 实现已被弃用。它将不再添加任何新功能。取而代之的是,一个运行在 Node.js 上、完全用 TypeScript 编写的 Nymph 新版本将取代 PHP 实现。您可以在 Nymph.js 仓库 中找到它。

实时演示

尝试在两个窗口中打开相同的演示,并查看一个窗口如何更新为另一个窗口的更改。

应用模板

要使用 Nymph 开始构建应用程序,您可以使用 Nymph 应用程序模板

Nymph 实体

Nymph 通过将一个实体保存到另一个实体的属性中来处理实体之间的关系。

// Creating entities is super easy.
async function createBlogPost(title, body, archived) {
  // BlogPost extends Entity.
  const post = new BlogPost();
  post.title = title;
  post.body = body;
  post.archived = archived;
  await post.$save();
  // The post is now saved in the database.
  return post;
}

// Creating relationships is also easy.
async function createBlogPostComment(post, body) {
  if (!(post instanceof BlogPost)) {
    throw new Error("post should be a BlogPost object!");
  }

  const comment = new Comment();
  comment.post = post;
  comment.body = body;
  await comment.$save();
  return comment;
}

const post = await createBlogPost(
  "My First Post",
  "This is a great blog post!",
  false
);
await createBlogPostComment(post, "It sure is! Wow!");

Nymph 查询语言

Nymph 使用基于对象的查询语言。它与波兰符号类似,如 'operator' : ['operand', 'operand']

// Object based queries are easy from the frontend.
async function searchBlogPosts(userQuery, page = 0) {
  // The server will only return entities the user has access to.
  return await Nymph.getEntities(
    {
      class: BlogPost.class,
      limit: 10,
      offset: page * 10,
    },
    {
      type: "&",
      // You can do things like pattern matching.
      like: ["title", "%" + userQuery + "%"],
      // Or strict comparison, etc.
      strict: ["archived", false],
    }
  );
}

// Querying relationships is also easy.
async function getBlogPostComments(post) {
  return await Nymph.getEntities(
    {
      class: BlogPostComment.class,
    },
    {
      type: "&",
      ref: ["post", post],
    }
  );
}

// Complicated queries are easy.
async function getMyLatestCommentsForPosts(posts) {
  return await Nymph.getEntities(
    {
      // Get all comments...
      class: BlogPostComment.class,
    },
    {
      type: "&",
      // ...made in the last day...
      gte: ["cdate", null, "-1 day"],
      // ...where the current user is the author...
      ref: ["user", await User.current()],
    },
    {
      // ...and the comment is on any...
      type: "|",
      // ...of the given posts.
      ref: posts.map((post) => ["post", post]),
    }
  );
}

Nymph PubSub

使用 PubSub 服务器制作协作应用程序变得非常简单。

function watchBlogPostComments(post, component) {
  const comments = component.state.comments || [];

  const subscription = Nymph.getEntities(
    {
      class: BlogPostComment.class,
    },
    {
      type: "&",
      ref: ["post", post],
    }
  ).subscribe((update) => {
    // The PubSub server keeps us up to date on this query.
    PubSub.updateArray(comments, update);
    component.setState({ comments });
  });

  component.onDestroy(() => {
    subscription.unsubscribe();
  });
}

用户/组管理

Tilmeld 是 Nymph 的用户管理系统。请访问 tilmeld.org 查看详细信息。

安装

如果您想使用 Nymph 构建应用程序,您可以使用 应用程序模板

您还可以按照服务器和客户端仓库中的说明或在 Nymph 的 设置指南PubSub 中提供的说明在现有应用程序中安装 Nymph。

Nymph Server PubSub Server Tilmeld Server Browser Client Node.js Client Tilmeld Client App Examples

开发环境安装

如果您对在 Nymph 本身上工作感兴趣

  1. 获取 Docker
    • 您可以在 Linux 上使用以下命令运行 Docker 安装脚本
      curl -fsSL https://get.docker.com -o get-docker.sh
      sh get-docker.sh
    • 或者,从 Ubuntu 的仓库
      sudo apt-get install docker.io
      sudo usermod -a -G docker $USER
      然后注销并重新登录。
  2. 获取 Docker Compose
    • 从 Ubuntu 的仓库
      sudo apt-get install docker-compose
  3. 克隆仓库
    git clone --recursive https://github.com/sciactive/nymph.git
    cd nymph
  4. 确保子模块位于 master 分支
    git submodule foreach git checkout master
  5. 运行应用程序
    ./run.sh

现在您可以在本地计算机上看到示例应用程序

API 文档

请参阅 Wiki 中的 API 文档