session.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { entityKind } from "../../entity.js";
  2. import { NoopLogger } from "../../logger.js";
  3. import { MySqlPreparedQuery, MySqlSession } from "../../mysql-core/index.js";
  4. import { fillPlaceholders } from "../../sql/sql.js";
  5. class PrismaMySqlPreparedQuery extends MySqlPreparedQuery {
  6. constructor(prisma, query, logger) {
  7. super(void 0, void 0, void 0);
  8. this.prisma = prisma;
  9. this.query = query;
  10. this.logger = logger;
  11. }
  12. iterator(_placeholderValues) {
  13. throw new Error("Method not implemented.");
  14. }
  15. static [entityKind] = "PrismaMySqlPreparedQuery";
  16. execute(placeholderValues) {
  17. const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
  18. this.logger.logQuery(this.query.sql, params);
  19. return this.prisma.$queryRawUnsafe(this.query.sql, ...params);
  20. }
  21. }
  22. class PrismaMySqlSession extends MySqlSession {
  23. constructor(dialect, prisma, options) {
  24. super(dialect);
  25. this.prisma = prisma;
  26. this.options = options;
  27. this.logger = options.logger ?? new NoopLogger();
  28. }
  29. static [entityKind] = "PrismaMySqlSession";
  30. logger;
  31. execute(query) {
  32. return this.prepareQuery(this.dialect.sqlToQuery(query)).execute();
  33. }
  34. all(_query) {
  35. throw new Error("Method not implemented.");
  36. }
  37. prepareQuery(query) {
  38. return new PrismaMySqlPreparedQuery(this.prisma, query, this.logger);
  39. }
  40. transaction(_transaction, _config) {
  41. throw new Error("Method not implemented.");
  42. }
  43. }
  44. export {
  45. PrismaMySqlPreparedQuery,
  46. PrismaMySqlSession
  47. };
  48. //# sourceMappingURL=session.js.map