medz / prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
https://prisma.pub
BSD 3-Clause "New" or "Revised" License
436 stars 29 forks source link

feat(client): Support `omit` option to queries #389

Open medz opened 3 weeks ago

medz commented 3 weeks ago

Protocol 1 (omit(true)):

{
      modelName: 'User',
      action: 'findMany',
      previewFeatures: ['omitApi'],
      args: { omit: { name: true } },
}

->

{
      "modelName": "User",
      "action": "findMany",
      "query": {
        "arguments": {},
        "selection": {
          "$composites": true,
          "$scalars": true,
          "name": false
        }
      }
 }

Protocol 2 (omit(false)):

{
      modelName: 'User',
      action: 'findMany',
      previewFeatures: ['omitApi'],
      args: { omit: { name: false } },
 }

->

{
      "modelName": "User",
      "action": "findMany",
      "query": {
        "arguments": {},
        "selection": {
          "$composites": true,
          "$scalars": true,
          "name": true
        }
      }
    }

Protocel 3 (omit + include):

{
      modelName: 'User',
      action: 'findMany',
      previewFeatures: ['omitApi'],
      args: { include: { posts: { omit: { title: true } } } },
    }

{
      "modelName": "User",
      "action": "findMany",
      "query": {
        "arguments": {},
        "selection": {
          "$composites": true,
          "$scalars": true,
          "posts": {
            "arguments": {},
            "selection": {
              "$composites": true,
              "$scalars": true,
              "title": false
            }
          }
        }
      }
    }

More see 👉 https://github.com/prisma/prisma/pull/23770/files#diff-ff0c0eab8c9ab531a46770b84e6254a67f0cf40fb9d4ceb1c5f7c17f497c1633