Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
feathers-prisma
Advanced tools
Readme
npm install feathers-prisma --save
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).
feathers-prisma
v0.6.0feathers-prisma
v0.7.0 or higherimport 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
)
);
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"],
},
},
});
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,
},
},
},
},
});
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" }]);
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",
},
},
});
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";
Copyright (c) 2021.
Licensed under the MIT license.
FAQs
A Feathers service adapter for Prisma ORM.
The npm package feathers-prisma receives a total of 24 weekly downloads. As such, feathers-prisma popularity was classified as not popular.
We found that feathers-prisma demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.