session.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { entityKind } from "../../entity.js";
  2. import { NoopLogger } from "../../logger.js";
  3. import { fillPlaceholders } from "../../sql/sql.js";
  4. import { SQLitePreparedQuery, SQLiteSession } from "../../sqlite-core/index.js";
  5. class PrismaSQLitePreparedQuery extends SQLitePreparedQuery {
  6. constructor(prisma, query, logger, executeMethod) {
  7. super("async", executeMethod, query);
  8. this.prisma = prisma;
  9. this.logger = logger;
  10. }
  11. static [entityKind] = "PrismaSQLitePreparedQuery";
  12. all(placeholderValues) {
  13. const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
  14. this.logger.logQuery(this.query.sql, params);
  15. return this.prisma.$queryRawUnsafe(this.query.sql, ...params);
  16. }
  17. async run(placeholderValues) {
  18. await this.all(placeholderValues);
  19. return [];
  20. }
  21. async get(placeholderValues) {
  22. const all = await this.all(placeholderValues);
  23. return all[0];
  24. }
  25. values(_placeholderValues) {
  26. throw new Error("Method not implemented.");
  27. }
  28. isResponseInArrayMode() {
  29. return false;
  30. }
  31. }
  32. class PrismaSQLiteSession extends SQLiteSession {
  33. constructor(prisma, dialect, options) {
  34. super(dialect);
  35. this.prisma = prisma;
  36. this.logger = options.logger ?? new NoopLogger();
  37. }
  38. static [entityKind] = "PrismaSQLiteSession";
  39. logger;
  40. prepareQuery(query, fields, executeMethod) {
  41. return new PrismaSQLitePreparedQuery(this.prisma, query, this.logger, executeMethod);
  42. }
  43. transaction(_transaction, _config) {
  44. throw new Error("Method not implemented.");
  45. }
  46. }
  47. export {
  48. PrismaSQLitePreparedQuery,
  49. PrismaSQLiteSession
  50. };
  51. //# sourceMappingURL=session.js.map