1 line
8.3 KiB
JSON
1 line
8.3 KiB
JSON
|
{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.stmtToProto = exports.Stmt = void 0;\nconst sql_js_1 = require(\"./sql.js\");\nconst value_js_1 = require(\"./value.js\");\n/** A statement that can be evaluated by the database. Besides the SQL text, it also contains the positional\n * and named arguments. */\nclass Stmt {\n /** The SQL statement text. */\n sql;\n /** @private */\n _args;\n /** @private */\n _namedArgs;\n /** Initialize the statement with given SQL text. */\n constructor(sql) {\n this.sql = sql;\n this._args = [];\n this._namedArgs = new Map();\n }\n /** Binds positional parameters from the given `values`. All previous positional bindings are cleared. */\n bindIndexes(values) {\n this._args.length = 0;\n for (const value of values) {\n this._args.push((0, value_js_1.valueToProto)(value));\n }\n return this;\n }\n /** Binds a parameter by a 1-based index. */\n bindIndex(index, value) {\n if (index !== (index | 0) || index <= 0) {\n throw new RangeError(\"Index of a positional argument must be positive integer\");\n }\n while (this._args.length < index) {\n this._args.push(null);\n }\n this._args[index - 1] = (0, value_js_1.valueToProto)(value);\n return this;\n }\n /** Binds a parameter by name. */\n bindName(name, value) {\n this._namedArgs.set(name, (0, value_js_1.valueToProto)(value));\n return this;\n }\n /** Clears all bindings. */\n unbindAll() {\n this._args.length = 0;\n this._namedArgs.clear();\n return this;\n }\n}\nexports.Stmt = Stmt;\nfunction stmtToProto(sqlOwner, stmt, wantRows) {\n let inSql;\n let args = [];\n let namedArgs = [];\n if (stmt instanceof Stmt) {\n inSql = stmt.sql;\n args = stmt._args;\n for (const [name, value] of stmt._namedArgs.entries()) {\n namedArgs.push({\n name,\n value\n });\n }\n } else if (Array.isArray(stmt)) {\n inSql = stmt[0];\n if (Array.isArray(stmt[1])) {\n args = stmt[1].map(arg => (0, value_js_1.valueToProto)(arg));\n } else {\n namedArgs = Object.entries(stmt[1]).map(([name, value]) => {\n return {\n name,\n value: (0, value_js_1.valueToProto)(value)\n };\n });\n }\n } else {\n inSql = stmt;\n }\n const {\n sql,\n sqlId\n } = (0, sql_js_1.sqlToProto)(sqlOwner, inSql);\n return {\n sql,\n sqlId,\n args,\n namedArgs,\n wantRows\n };\n}\nexports.stmtToProto = stmtToProto;","map":{"version":3,"names":["Object","defineProperty","exports","value","stmtToProto","Stmt","sql_js_1","require","value_js_1","sql","_args","_namedArgs","constructor","Map","bindIndexes","values","length","push","valueToProto","bindIndex","index","RangeError","bindName","name","set","unbindAll","clear","sqlOwner","stmt","wantRows","inSql","args","namedArgs","entries","Array","isArray","map","arg","sqlId","sqlToProto"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-cjs/stmt.js"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.stmtToProto = exports.Stmt = void 0;\nconst sql_js_1 = require(\"./sql.js\");\nconst value_js_1 = require(\"./value.js\");\n/** A statement that can be evaluated by the database. Besides the SQL text, it also contains the positional\n * and named arguments. */\nclass Stmt {\n /** The SQL statement text. */\n sql;\n /** @private */\n _args;\n /** @private */\n _namedArgs;\n /** Initialize the statement with given SQL text. */\n constructor(sql) {\n this.sql = sql;\n this._args = [];\n this._namedArgs = new Map();\n }\n /** Binds positional parameters from the given `values`. All previous positional bindings are cleared. */\n bindIndexes(values) {\n this._args.length = 0;\n for (const value of values) {\n this._args.push((0, value_js_1.valueToProto)(value));\n }\n return this;\n }\n /** Bind
|