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

feathers-prisma

v0.7.0

Published

A Feathers service adapter for Prisma ORM.

Downloads

158

Readme

feathers-prisma

libraries.io Code Climate Test Coverage npm

A Feathers service adapter for Prisma ORM.

Installation

npm install feathers-prisma --save

Documentation

This adapter supports all methods (create, delete, update, patch, find, get) and the common way for querying (equality, $limit, $skip, $sort, $select, $in, $nin, $lt, $lte, $gt, $gte, $ne, $or, $and). Also supports eager loading ($eager), full-text search ($search) and prisma filtering (from 0.7.0 on with $prisma, previously with $rawWhere which is now deprecated).

Prisma Version

  • Prisma v3 use feathers-prisma v0.6.0
  • Prisma v5 use feathers-prisma v0.7.0 or higher

Setup

import feathers from "@feathersjs/feathers";
import { service } from "feathers-prisma";
import { PrismaClient } from "@prisma/client";

// Initialize the application
const app = feathers();

// Initialize the plugin
const prismaClient = new PrismaClient();
prismaClient.$connect();
app.set("prisma", prismaClient);

const paginate = {
  default: 10,
  max: 50,
};

app.use(
  "/messages",
  service(
    {
      model: "messages",
      paginate,
      multi: ["create", "patch", "remove"],
      whitelist: ["$eager"],
    },
    prismaClient
  )
);

Eager Loading / Relation Queries

Relations can be resolved via $eager property in your query. It supports also deep relations. The $eager property has to be set in the whitelist option parameter. Otherwise the service will throw an error.

app.use(
  "/messages",
  service(
    {
      model: "message",
      whitelist: ["$eager"],
    },
    prismaClient
  )
);
// will load the recipients with the related user
// as well as all attachments  of the messages
app.service("messages").find({
  query: {
    $eager: [["recipients", ["user"]], "attachments"],
  },
});
// selecting specific fields is also supported since 0.4.0
app.service("messages").find({
  query: {
    $eager: {
      recipients: ["receivedAt", "user"],
    },
  },
});

Filter with default prisma filters

Since 0.5.0 it is possible to use default prisma filters. This makes it possible to filter JSON fields or to filter relations.

The $prisma property has to be set in the whitelist option parameter. Otherwise the service will throw an error.

Since 0.7.0 use the $prisma property to filter instead of using the $rawWhere property.

app.use(
  "/messages",
  service(
    {
      model: "message",
      whitelist: ["$prisma"],
    },
    prismaClient
  )
);
// will load all messages where at least one of the recipients userIds is equal 1
app.service("messages").find({
  query: {
    recipients: {
      $prisma: {
        some: {
          userId: 1,
        },
      },
    },
  },
});

Batch requests

This adapter supports batch requests. This is possible by allowing this in the multi property in the service options. Supported methods are create, patch and delete.

app.use(
  "/messages",
  service(
    {
      model: "messages",
      multi: ["create", "patch", "delete"],
    },
    prismaClient
  )
);

app.service("messages").create([{ body: "Lorem" }, { body: "Ipsum" }]);

Full-Text Search

Prisma supports a full-text search which is currently in preview mode. Find out more how to activate it here. If you activated it through your schema you have to allow it in the whitelist property:

app.use(
  "/messages",
  service(
    {
      model: "messages",
      whitelist: ["$search"],
    },
    prismaClient
  )
);

app.service("messages").find({
  query: {
    body: {
      $search: "hello | hola",
    },
  },
});

Complete Example

Here's an example of a Feathers server that uses feathers-prisma.

import feathers from "@feathersjs/feathers";
import { service } from "feathers-prisma";

// Initialize the application
const app = feathers();

// Initialize the plugin
const prismaClient = new PrismaClient();
prismaClient.$connect();
app.set("prisma", prismaClient);

const paginate = {
  default: 10,
  max: 50,
};

app.use(
  "/messages",
  service(
    {
      model: "messages",
      paginate,
      multi: ["create", "patch", "remove"],
      whitelist: ["$eager"],
    },
    prismaClient
  )
);
// Or if you want to extend the service class
import { PrismaService } from "feathers-prisma";

License

Copyright (c) 2021.

Licensed under the MIT license.