Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kakasoo/sortable

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kakasoo/sortable

## getSortable

  • 1.0.8
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

sortable

getSortable

$ npm i @kakasoo/sortable

This is very simple function to create object for make prisma orderBy statement. For example, you can just write user.articles.created_at as parameter, like below code.

getSortable("user.articles.created_at", "desc"); // { user: { articles: { created_at: "desc" } } }

Because it is a type inference, it is much easier to use if you create and use a function in advance.

namespace IUser {
  namespace IRequest {
    type SortbaleColumns =
      | "user.articles.created_at"
      | "user.articles.updated_at";
  }
}

export const orderBy = <T extends IUser.IRequest.SortableColumns>(
  key: T,
  direction: "asc" | "desc"
) => {
  return getSortable(
    key,
    direction
  ) satisfies Prisma.usersOrderByWithRelationInput;
};

then, You can use like it, Right?

prisma.user.findMany({
  orderBy: orderBy("user.articles.created_at", "desc"),
});

createSortable

interface Example {
  user: {
    name: string;
    createdAt: string;
  };
}

// #1
const sortable = createSortable<Example>();
sortable("user.createdAt", "asc"); // It guarantees type inference.

// #2
// also you can use like this:
createSortable<Example>()("user.createdAt", "asc");

FAQs

Package last updated on 12 Jan 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc