Core ConceptsPrisma ORM

Custom Queries

As Arkos generates Prisma Model Routes, it also allows you to customize the underlying Prisma queries for each operation without handrolling your own controller logic. This is done through a [model].query.ts file that Arkos picks up automatically at boot time.

Setup

Create a query options file for your model:

src/modules/post/post.query.ts
import { PrismaQueryOptions } from "arkos/prisma";
import { prisma } from "@/src/utils/prisma";

const postQueryOptions: PrismaQueryOptions<typeof prisma.post> = {
  global: {
    where: { published: true },
    orderBy: { createdAt: "desc" },
  },
};

export default postQueryOptions;

Or generate it with the CLI:

npx arkos generate query-options --module post
# shorthand
npx arkos g q -m post

Configuration Keys

Options are applied in this priority order — higher overrides lower:

  1. Request query parameters (always highest)
  2. Individual operation keys (findMany, createOne, etc.)
  3. Grouped operation keys (find, save, create, etc.)
  4. global

Grouped Keys

KeyApplies To
findfindOne, findMany
savecreateOne, updateOne, createMany, updateMany
createcreateOne, createMany
updateupdateOne, updateMany
deletedeleteOne, deleteMany
saveOnecreateOne, updateOne
saveManycreateMany, updateMany

Individual Keys

findOne, findMany, createOne, updateOne, deleteOne, createMany, updateMany, deleteMany

Each key accepts the full Prisma options for that operation — select, include, omit, where, orderBy, take, skip, distinct.

Options are deep-merged at each level, not replaced. Request query parameters always win but non-conflicting options from your config are preserved.

Examples

Excluding sensitive fields

src/modules/user/user.query.ts
import { PrismaQueryOptions } from "arkos/prisma";
import { prisma } from "@/src/utils/prisma";

const userQueryOptions: PrismaQueryOptions<typeof prisma.user> = {
  global: {
    omit: {
      password: true,
      resetToken: true,
    },
  },
};

export default userQueryOptions;

Different behavior per operation

src/modules/post/post.query.ts
import { PrismaQueryOptions } from "arkos/prisma";
import { prisma } from "@/src/utils/prisma";

const postQueryOptions: PrismaQueryOptions<typeof prisma.post> = {
  find: {
    where: { published: true },
    orderBy: { createdAt: "desc" },
  },
  findMany: {
    take: 10,
    select: {
      id: true,
      title: true,
      excerpt: true,
      createdAt: true,
    },
  },
  findOne: {
    include: {
      author: true,
      comments: {
        where: { approved: true },
        orderBy: { createdAt: "asc" },
      },
      tags: true,
    },
  },
  save: {
    include: { author: true, tags: true },
  },
};

export default postQueryOptions;