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

query-string-prisma-ume

v1.1.6

Published

Parse query for prisma

Downloads

3

Readme

Certainly! Here are the three utility functions (prismaOrderByToJsonString, prismaSelectToJsonString, and prismaWhereConditionToJsonString) with explanations in Markdown format that you can include in your README.md file:


Prisma Utility Functions

This documentation provides information about three utility functions for working with Prisma queries: prismaOrderByToJsonString, prismaSelectToJsonString, and prismaWhereConditionToJsonString. These functions help you convert Prisma query objects into JSON strings for use in your application.

Installation

These utility functions can be used in any TypeScript/typeScript project. To use them, follow these steps:

  1. Install the required packages (Prisma may need to be installed separately):
npm install query-string-prisma-ume
  1. Import the utility functions into your project:
import {
  prismaOrderByToJsonString,
  prismaSelectToJsonString,
  prismaWhereConditionToJsonString,
} from "query-string-prisma-ume";

Functions

Interface for example

// ./interfaces
interface UserResponse {
  id: string;
  dob: string;
  name: string;
  address: string;
  age: number;
  isActivated: boolean;
  posts?: Array<PostResponse>;
  comments?: Array<CommentResponse>;
}

interface PostResponse {
  id: string;
  userId: string;
  slug: string;
  title: string;
  content: string;
  date: Date;
  tags: Array<string>;
  user?: UserResponse;
  comments?: Array<CommentResponse>;
}

interface CommentResponse {
  id: string;
  userId: string;
  postId: string;
  user?: UserResponse;
  post?: PostResponse;
}

1. prismaOrderByToJsonString

Description

Converts a Prisma orderBy object to a JSON string.

Parameters

  • input (type: PrismaOrderByType): The Prisma orderBy object to convert.

Example

import {
  prismaOrderByToJsonString,
  PrismaOrderByType,
} from "query-string-prisma-ume";
import { UserResponse } from "./interfaces";

const orderBy: PrismaOrderByType<UserResponse> = {
  name: "asc",
  age: "desc",
};

const jsonString = prismaOrderByToJsonString<UserResponse>(orderBy);
console.log(jsonString); // Output: '{"name":"asc","age":"desc"}'

2. prismaSelectToJsonString

Description

Converts a Prisma select object to a JSON string.

Parameters

  • jsonArray (type: PrismaSelectType): The Prisma select object to convert.

Example

import { prismaSelectToJsonString } from "query-string-prisma-ume";
import { UserResponse } from "./interfaces";
// Define a complex Prisma select type
const complexSelect: PrismaSelectType<UserResponse> = [
  "$all", // Select all fields of UserResponse

  // Select comments with specific properties, including user details
  {
    comments: [
      "$all",
      {
        user: ["id", "name"],
      },
    ],
  },

  // Select posts with specific properties
  {
    posts: ["id", "title", "content", "tags"],
  },
];

// Convert the select type to a JSON string
const complexSelectJson = prismaSelectToJsonString<UserResponse>(complexSelect);

console.log(complexSelectJson);

3. prismaWhereConditionToJsonString

Description

Converts a Prisma where condition object to a JSON string.

Parameters

  • filter (type: PrismaWhereConditionType): The Prisma where condition object to convert.

Example

import {
  prismaWhereConditionToJsonString,
  PrismaWhereConditionType,
} from "query-string-prisma-ume";
import { UserResponse } from "./interfaces";

const filter: PrismaWhereConditionType<UserResponse> = {
  name: {
    contains: "John",
  },
  address: {
    contains: "ho chi minh",
    mode: "insensitive",
  },
  age: {
    gt: 30,
  },
};

const jsonString = prismaWhereConditionToJsonString<UserResponse>(filter);
console.log(jsonString); // Output: '{"filter":{"name":{"contains":"John","address":{"contains":"ho chi minh","mode":"insensitive"}},"age":{"gt":30}}}'

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

[Do Tran Minh Chu]

Acknowledgments

  • Prisma - For the Prisma ORM that these utilities work with.

Feel free to replace [Do Tran Minh Chu] in the author section with your actual name or your project's author information. This README provides a basic structure that you can expand upon to include more details or explanations if needed.