the-forest/client/node_modules/.cache/babel-loader/1a22dca38f2e6ef6a45be09414e6b423a20ea3e02ee1c09a7b491b58744e94cf.json
2024-09-17 20:35:18 -04:00

1 line
7.3 KiB
JSON

{"ast":null,"code":"import { sqlToProto } from \"./sql.js\";\nimport { valueToProto } from \"./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. */\nexport class 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(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] = valueToProto(value);\n return this;\n }\n /** Binds a parameter by name. */\n bindName(name, value) {\n this._namedArgs.set(name, 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}\nexport function 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 => valueToProto(arg));\n } else {\n namedArgs = Object.entries(stmt[1]).map(([name, value]) => {\n return {\n name,\n value: valueToProto(value)\n };\n });\n }\n } else {\n inSql = stmt;\n }\n const {\n sql,\n sqlId\n } = sqlToProto(sqlOwner, inSql);\n return {\n sql,\n sqlId,\n args,\n namedArgs,\n wantRows\n };\n}","map":{"version":3,"names":["sqlToProto","valueToProto","Stmt","sql","_args","_namedArgs","constructor","Map","bindIndexes","values","length","value","push","bindIndex","index","RangeError","bindName","name","set","unbindAll","clear","stmtToProto","sqlOwner","stmt","wantRows","inSql","args","namedArgs","entries","Array","isArray","map","arg","Object","sqlId"],"sources":["/Users/shoofle/Projects/the-forest/node_modules/@libsql/hrana-client/lib-esm/stmt.js"],"sourcesContent":["import { sqlToProto } from \"./sql.js\";\nimport { valueToProto } from \"./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. */\nexport class 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(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] = valueToProto(value);\n return this;\n }\n /** Binds a parameter by name. */\n bindName(name, value) {\n this._namedArgs.set(name, 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}\nexport function 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) => valueToProto(arg));\n }\n else {\n namedArgs = Object.entries(stmt[1]).map(([name, value]) => {\n return { name, value: valueToProto(value) };\n });\n }\n }\n else {\n inSql = stmt;\n }\n const { sql, sqlId } = sqlToProto(sqlOwner, inSql);\n return { sql, sqlId, args, namedArgs, wantRows };\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,UAAU;AACrC,SAASC,YAAY,QAAQ,YAAY;AACzC;AACA;AACA,OAAO,MAAMC,IAAI,CAAC;EACd;EACAC,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,MAAMC,KAAK,IAAIF,MAAM,EAAE;MACxB,IAAI,CAACL,KAAK,CAACQ,IAAI,CAACX,YAAY,CAACU,KAAK,CAAC,CAAC;IACxC;IACA,OAAO,IAAI;EACf;EACA;EACAE,SAASA,CAACC,KAAK,EAAEH,KAAK,EAAE;IACpB,IAAIG,KAAK,MAAMA,KAAK,GAAG,CAAC,CAAC,IAAIA,KAAK,IAAI,CAAC,EAAE;MACrC,MAAM,IAAIC,UAAU,CAAC,yDAAyD,CAAC;IACnF;IACA,OAAO,IAAI,CAACX,KAAK,CAACM,MAAM,GAAGI,KAAK,EAAE;MAC9B,IAAI,CAACV,KAAK,CAACQ,IAAI,CAAC,IAAI,CAAC;IACzB;IACA,IAAI,CAACR,KAAK,CAACU,KAAK,GAAG,CAAC,CAAC,GAAGb,YAAY,CAACU,KAAK,CAAC;IAC3C,OAAO,IAAI;EACf;EACA;EACAK,QAAQA,CAACC,IAAI,EAAEN,KAAK,EAAE;IAClB,IAAI,CAACN,UAAU,CAACa,GAAG,CAACD,IAAI,EAAEhB,YAAY,CAACU,KAA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