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 /** 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({ name, 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 }\n else {\n namedArgs = Object.entries(stmt[1]).map(([name, value]) => {\n return { name, value: (0, value_js_1.valueToProto)(value) };\n });\n }\n }\n else {\n inSql = stmt;\n }\n const { sql, sqlId } = (0, sql_js_1.sqlToProto)(sqlOwner, inSql);\n return { sql, sqlId, args, namedArgs, wantRows };\n}\nexports.stmtToProto = stmtToProto;\n"],"mappings":"AAAA,YAAY;;AACZA,MAAM,CAACC,cAAc,CAACC,OAAO,EAAE,YAAY,EAAE;EAAEC,KAAK,EAAE;AAAK,CAAC,CAAC;AAC7DD,OAAO,CAACE,WAAW,GAAGF,OAAO,CAACG,IAAI,GAAG,KAAK,CAAC;AAC3C,MAAMC,QAAQ,GAAGC,OAAO,CAAC,UAAU,CAAC;AACpC,MAAMC,UAAU,GAAGD,OAAO,CAAC,YAAY,CAAC;AACxC;AACA;AACA,MAAMF,IAAI,CAAC;EACP;EACAI,GAAG;EACH;EACAC,KAAK;EACL;EACAC,UAAU;EACV;EACAC,WAAWA,CAACH,GAAG,EAAE;IACb,IAAI,CAACA,GAAG,GAAGA,GAAG;IACd,IAAI,CAACC,KAAK,GAAG,EAAE;IACf,IAAI,CAACC,UAAU,GAAG,IAAIE,GAAG,CAAC,CAAC;EAC/B;EACA;EACAC,WAAWA,CAACC,MAAM,EAAE;IAChB,IAAI,CAACL,KAAK,CAACM,MAAM,GAAG,CAAC;IACrB,KAAK,MAAMb,KAAK,IAAIY,MAAM,EAAE;MACxB,IAAI,CAACL,KAAK,CAACO,IAAI,CAAC,CAAC,CAAC,EAAET,UAAU,CAACU,YAAY,EAAEf,KAAK,CAAC,CA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