[ExceptionsHandler] `$queryRaw` is a tag function,...
# orm-help
c
[ExceptionsHandler]
$queryRaw
is a tag function, please use it like the following: breaking with Prisma 3.1.1 - was working with prisma 2.x
Copy code
public RelatedClient = 'SELECT client.RelatedClientNumber [RelatedClientNumber], client.RelatedClientName [RelatedClientName], ' + 
    'splitbill.TimekeeperNumber [TimekeeperNumber], person.LastName [SplitBill_LastName], ' +
    'person.FirstName [SplitBill_FirstName] ';

public RelatedClientJoin = 'FROM ERP_ODS_Test.dbo.Client AS client ' +
    'INNER JOIN ERP_ODS_Test.dbo.SplitBillingAttorney AS splitbill ' +
    'ON client.ClientNumber = splitbill.ClientNumber  ' +
    'INNER JOIN dbo.Person AS person ' +
    'ON splitbill.TimekeeperNumber = person.TimekeeperNumber ';

public activeClient = "WHERE client.ClientActive = 1 AND splitbill.EmployeeActive = 1 ";

public Count = 'SELECT COUNT(*) ';
  
accessPrismaRaw(raw1: TemplateStringsArray, rawCount: TemplateStringsArray) {
    let Memory = [];
    const data = Promise.all([
      this.prisma.$queryRaw(raw1),
      this.prisma.$queryRaw(rawCount),
      Memory = this.appService.getMemory()
    ]).then(([records, total]) => {
      return {
        records,
        metadata: {
          count: total,
          memory: Memory
        },
      };
    });
    return data;
  }

  
async relatedclients(params: { searchString?: string; } = {}) {
    const { searchString } = params;
    let viewString = this.RelatedClient + this.RelatedClientJoin;
    let rawView;
    let rawCount;
    let searchFilter = this.activeClient + " AND client.RelatedClientName LIKE '%" + searchString + "%'";
    if (searchString) {
      rawView = this.RelatedClient + this.RelatedClientJoin + searchFilter;
      rawCount = this.Count + this.RelatedClientJoin + searchFilter;
    } else {
      rawView = this.RelatedClient + this.RelatedClientJoin + this.activeClient;
      rawCount = this.Count + this.RelatedClientJoin + this.activeClient;
    }
    return this.accessPrismaRaw(rawView, rawCount);
  }
The final script (rawView) = SELECT client.RelatedClientNumber [RelatedClientNumber], client.RelatedClientName [RelatedClientName], splitbill.TimekeeperNumber [TimekeeperNumber], person.LastName [SplitBill_LastName], person.FirstName [SplitBill_FirstName] FROM ERP_ODS_Test.dbo.Client AS client INNER JOIN ERP_ODS_Test.dbo.SplitBillingAttorney AS splitbill ON client.ClientNumber = splitbill.ClientNumber  INNER JOIN dbo.Person AS person ON splitbill.TimekeeperNumber = person.TimekeeperNumber WHERE client.ClientActive = 1 AND splitbill.EmployeeActive = 1  AND client.RelatedClientName LIKE '%google%' Works when run on the sql server. Change $queryRaw to $executeRawUnsafe - and the sql script executes.
Copy code
accessPrismaRaw(raw1: string, rawCount: string) {
    let Memory = [];
    const data = Promise.all([
      this.prisma.$executeRawUnsafe(raw1),
      this.prisma.$executeRawUnsafe(rawCount),
      Memory = this.appService.getMemory()
    ]).then(([records, total]) => {
      return {
        records,
        metadata: {
          count: total,
          memory: Memory
        },
      };
    });
    return data;
  }
Again, $queryRaw used to work in 2.x, but no longer in 3.1.1
r
@Chip Clark 👋 Have a look at the changes made to raw queries here