PHP 7.4.33
Preview: session.js Size: 7.29 KB
/var/www/gtechmarathon2026.bitkit.dk/httpdocs/node_modules/drizzle-orm/libsql/session.js
import { entityKind } from "../entity.js";
import { NoopLogger } from "../logger.js";
import { fillPlaceholders, sql } from "../sql/sql.js";
import { SQLiteTransaction } from "../sqlite-core/index.js";
import { SQLitePreparedQuery, SQLiteSession } from "../sqlite-core/session.js";
import { mapResultRow } from "../utils.js";
class LibSQLSession extends SQLiteSession {
  constructor(client, dialect, schema, options, tx) {
    super(dialect);
    this.client = client;
    this.schema = schema;
    this.options = options;
    this.tx = tx;
    this.logger = options.logger ?? new NoopLogger();
  }
  static [entityKind] = "LibSQLSession";
  logger;
  prepareQuery(query, fields, executeMethod, isResponseInArrayMode, customResultMapper) {
    return new LibSQLPreparedQuery(
      this.client,
      query,
      this.logger,
      fields,
      this.tx,
      executeMethod,
      isResponseInArrayMode,
      customResultMapper
    );
  }
  async batch(queries) {
    const preparedQueries = [];
    const builtQueries = [];
    for (const query of queries) {
      const preparedQuery = query._prepare();
      const builtQuery = preparedQuery.getQuery();
      preparedQueries.push(preparedQuery);
      builtQueries.push({ sql: builtQuery.sql, args: builtQuery.params });
    }
    const batchResults = await this.client.batch(builtQueries);
    return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));
  }
  async migrate(queries) {
    const preparedQueries = [];
    const builtQueries = [];
    for (const query of queries) {
      const preparedQuery = query._prepare();
      const builtQuery = preparedQuery.getQuery();
      preparedQueries.push(preparedQuery);
      builtQueries.push({ sql: builtQuery.sql, args: builtQuery.params });
    }
    const batchResults = await this.client.migrate(builtQueries);
    return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));
  }
  async transaction(transaction, _config) {
    const libsqlTx = await this.client.transaction();
    const session = new LibSQLSession(
      this.client,
      this.dialect,
      this.schema,
      this.options,
      libsqlTx
    );
    const tx = new LibSQLTransaction("async", this.dialect, session, this.schema);
    try {
      const result = await transaction(tx);
      await libsqlTx.commit();
      return result;
    } catch (err) {
      await libsqlTx.rollback();
      throw err;
    }
  }
  extractRawAllValueFromBatchResult(result) {
    return result.rows;
  }
  extractRawGetValueFromBatchResult(result) {
    return result.rows[0];
  }
  extractRawValuesValueFromBatchResult(result) {
    return result.rows;
  }
}
class LibSQLTransaction extends SQLiteTransaction {
  static [entityKind] = "LibSQLTransaction";
  async transaction(transaction) {
    const savepointName = `sp${this.nestedIndex}`;
    const tx = new LibSQLTransaction("async", this.dialect, this.session, this.schema, this.nestedIndex + 1);
    await this.session.run(sql.raw(`savepoint ${savepointName}`));
    try {
      const result = await transaction(tx);
      await this.session.run(sql.raw(`release savepoint ${savepointName}`));
      return result;
    } catch (err) {
      await this.session.run(sql.raw(`rollback to savepoint ${savepointName}`));
      throw err;
    }
  }
}
class LibSQLPreparedQuery extends SQLitePreparedQuery {
  constructor(client, query, logger, fields, tx, executeMethod, _isResponseInArrayMode, customResultMapper) {
    super("async", executeMethod, query);
    this.client = client;
    this.logger = logger;
    this.fields = fields;
    this.tx = tx;
    this._isResponseInArrayMode = _isResponseInArrayMode;
    this.customResultMapper = customResultMapper;
    this.customResultMapper = customResultMapper;
    this.fields = fields;
  }
  static [entityKind] = "LibSQLPreparedQuery";
  run(placeholderValues) {
    const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
    this.logger.logQuery(this.query.sql, params);
    const stmt = { sql: this.query.sql, args: params };
    return this.tx ? this.tx.execute(stmt) : this.client.execute(stmt);
  }
  async all(placeholderValues) {
    const { fields, logger, query, tx, client, customResultMapper } = this;
    if (!fields && !customResultMapper) {
      const params = fillPlaceholders(query.params, placeholderValues ?? {});
      logger.logQuery(query.sql, params);
      const stmt = { sql: query.sql, args: params };
      return (tx ? tx.execute(stmt) : client.execute(stmt)).then(({ rows: rows2 }) => this.mapAllResult(rows2));
    }
    const rows = await this.values(placeholderValues);
    return this.mapAllResult(rows);
  }
  mapAllResult(rows, isFromBatch) {
    if (isFromBatch) {
      rows = rows.rows;
    }
    if (!this.fields && !this.customResultMapper) {
      return rows.map((row) => normalizeRow(row));
    }
    if (this.customResultMapper) {
      return this.customResultMapper(rows, normalizeFieldValue);
    }
    return rows.map((row) => {
      return mapResultRow(
        this.fields,
        Array.prototype.slice.call(row).map((v) => normalizeFieldValue(v)),
        this.joinsNotNullableMap
      );
    });
  }
  async get(placeholderValues) {
    const { fields, logger, query, tx, client, customResultMapper } = this;
    if (!fields && !customResultMapper) {
      const params = fillPlaceholders(query.params, placeholderValues ?? {});
      logger.logQuery(query.sql, params);
      const stmt = { sql: query.sql, args: params };
      return (tx ? tx.execute(stmt) : client.execute(stmt)).then(({ rows: rows2 }) => this.mapGetResult(rows2));
    }
    const rows = await this.values(placeholderValues);
    return this.mapGetResult(rows);
  }
  mapGetResult(rows, isFromBatch) {
    if (isFromBatch) {
      rows = rows.rows;
    }
    const row = rows[0];
    if (!this.fields && !this.customResultMapper) {
      return normalizeRow(row);
    }
    if (!row) {
      return void 0;
    }
    if (this.customResultMapper) {
      return this.customResultMapper(rows, normalizeFieldValue);
    }
    return mapResultRow(
      this.fields,
      Array.prototype.slice.call(row).map((v) => normalizeFieldValue(v)),
      this.joinsNotNullableMap
    );
  }
  values(placeholderValues) {
    const params = fillPlaceholders(this.query.params, placeholderValues ?? {});
    this.logger.logQuery(this.query.sql, params);
    const stmt = { sql: this.query.sql, args: params };
    return (this.tx ? this.tx.execute(stmt) : this.client.execute(stmt)).then(({ rows }) => rows);
  }
  /** @internal */
  isResponseInArrayMode() {
    return this._isResponseInArrayMode;
  }
}
function normalizeRow(obj) {
  return Object.keys(obj).reduce((acc, key) => {
    if (Object.prototype.propertyIsEnumerable.call(obj, key)) {
      acc[key] = obj[key];
    }
    return acc;
  }, {});
}
function normalizeFieldValue(value) {
  if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) {
    if (typeof Buffer !== "undefined") {
      if (!(value instanceof Buffer)) {
        return Buffer.from(value);
      }
      return value;
    }
    if (typeof TextDecoder !== "undefined") {
      return new TextDecoder().decode(value);
    }
    throw new Error("TextDecoder is not available. Please provide either Buffer or TextDecoder polyfill.");
  }
  return value;
}
export {
  LibSQLPreparedQuery,
  LibSQLSession,
  LibSQLTransaction
};
//# sourceMappingURL=session.js.map

Directory Contents

Dirs: 6 × Files: 30
Name Size Perms Modified Actions
http DIR
- drwxr-xr-x 2025-07-10 12:55:00
Edit Download
node DIR
- drwxr-xr-x 2025-07-10 12:55:00
Edit Download
sqlite3 DIR
- drwxr-xr-x 2025-07-10 12:55:00
Edit Download
wasm DIR
- drwxr-xr-x 2025-07-10 12:55:00
Edit Download
web DIR
- drwxr-xr-x 2025-07-10 12:55:00
Edit Download
ws DIR
- drwxr-xr-x 2025-07-10 12:55:00
Edit Download
2.40 KB lrw-r--r-- 2025-07-10 12:54:57
Edit Download
3.06 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
530 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
527 B lrw-r--r-- 2025-07-10 12:55:00
Edit Download
1.31 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
3.05 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
2.17 KB lrw-r--r-- 2025-07-10 12:54:57
Edit Download
2.48 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
866 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
863 B lrw-r--r-- 2025-07-10 12:55:00
Edit Download
942 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
2.42 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
1.18 KB lrw-r--r-- 2025-07-10 12:54:58
Edit Download
220 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
61 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
59 B lrw-r--r-- 2025-07-10 12:55:00
Edit Download
92 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
181 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
2.32 KB lrw-r--r-- 2025-07-10 12:54:58
Edit Download
2.32 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
251 B lrw-r--r-- 2025-07-10 12:54:59
Edit Download
249 B lrw-r--r-- 2025-07-10 12:55:00
Edit Download
1.23 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
2.29 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
8.59 KB lrw-r--r-- 2025-07-10 12:54:58
Edit Download
15.91 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
3.72 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
3.71 KB lrw-r--r-- 2025-07-10 12:55:00
Edit Download
7.29 KB lrw-r--r-- 2025-07-10 12:54:59
Edit Download
15.90 KB lrw-r--r-- 2025-07-10 12:55:00
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).