(query: ParseOpts)
| 70 | const emptyArray: any[] = [] |
| 71 | |
| 72 | const parse = (query: ParseOpts): Buffer => { |
| 73 | // expect something like this: |
| 74 | // { name: 'queryName', |
| 75 | // text: 'select * from blah', |
| 76 | // types: ['int8', 'bool'] } |
| 77 | |
| 78 | // normalize missing query names to allow for null |
| 79 | const name = query.name || '' |
| 80 | if (name.length > 63) { |
| 81 | console.error('Warning! Postgres only supports 63 characters for query names.') |
| 82 | console.error('You supplied %s (%s)', name, name.length) |
| 83 | console.error('This can cause conflicts and silent errors executing queries') |
| 84 | } |
| 85 | |
| 86 | const types = query.types || emptyArray |
| 87 | |
| 88 | const len = types.length |
| 89 | |
| 90 | const buffer = writer |
| 91 | .addCString(name) // name of query |
| 92 | .addCString(query.text) // actual query text |
| 93 | .addInt16(len) |
| 94 | |
| 95 | for (let i = 0; i < len; i++) { |
| 96 | buffer.addInt32(types[i]) |
| 97 | } |
| 98 | |
| 99 | return writer.flush(code.parse) |
| 100 | } |
| 101 | |
| 102 | type ValueMapper = (param: any, index: number) => any |
| 103 |
nothing calls this directly
no test coverage detected