|
| 1 | +module.exports = { |
| 2 | + |
| 3 | + |
| 4 | + friendlyName: 'Parse native query error', |
| 5 | + |
| 6 | + |
| 7 | + description: 'Attempt to identify and parse a raw error from sending a native query and normalize it to a standard error footprint.', |
| 8 | + |
| 9 | + |
| 10 | + cacheable: true, |
| 11 | + |
| 12 | + |
| 13 | + sync: true, |
| 14 | + |
| 15 | + |
| 16 | + inputs: { |
| 17 | + |
| 18 | + queryType: { |
| 19 | + description: 'The type of query operation this raw error came from.', |
| 20 | + extendedDescription: 'Either "select", "insert", "delete", or "update". This determines how the provided raw error will be parsed/coerced.', |
| 21 | + moreInfoUrl: 'https://github.com/particlebanana/waterline-query-builder/blob/master/docs/syntax.md', |
| 22 | + required: true, |
| 23 | + example: 'select',// (select|insert|delete|update) |
| 24 | + }, |
| 25 | + |
| 26 | + nativeQueryError: { |
| 27 | + description: 'The error sent back from the database as a result of a native query.', |
| 28 | + extendedDescription: 'This is referring to e.g. the output (`err`) returned through the `error` exit of `sendNativeQuery()` in this driver.', |
| 29 | + required: true, |
| 30 | + example: '===' |
| 31 | + }, |
| 32 | + |
| 33 | + meta: |
| 34 | + require('../constants/meta.input') |
| 35 | + |
| 36 | + }, |
| 37 | + |
| 38 | + |
| 39 | + exits: { |
| 40 | + |
| 41 | + success: { |
| 42 | + description: 'The normalization is complete. If the error cannot be normalized into any other more specific footprint, then the catchall footprint will be returned.', |
| 43 | + outputVariableName: 'report', |
| 44 | + outputDescription: 'The `footprint` property is the normalized "footprint" representing the provided raw error. Conforms to one of a handful of standardized footprint types expected by the Waterline driver interface. The `meta` property is reserved for custom adapter-specific extensions.', |
| 45 | + example: { |
| 46 | + footprint: {}, |
| 47 | + meta: '===' |
| 48 | + } |
| 49 | + }, |
| 50 | + |
| 51 | + }, |
| 52 | + |
| 53 | + |
| 54 | + fn: function (inputs, exits) { |
| 55 | + |
| 56 | + var footprint = { identity: 'catchall' }; |
| 57 | + switch (inputs.queryType){ |
| 58 | + case 'select': |
| 59 | + break; |
| 60 | + |
| 61 | + case 'insert': |
| 62 | + case 'update': |
| 63 | + // TODO: negotiate `notUnique` error. |
| 64 | + // |
| 65 | + // For implementation help w/ building `columns`, see: |
| 66 | + // • https://github.com/balderdashy/sails-postgresql/blob/a51b3643777dcf1af5517acbf76e09612d36b301/lib/adapter.js#L1308 |
| 67 | + // if (inputs.nativeQueryError.??????) { |
| 68 | + // footprint.identity = 'notUnique'; |
| 69 | + // footprint.columns = [ 'email_address' ]; |
| 70 | + // } |
| 71 | + break; |
| 72 | + |
| 73 | + case 'delete': |
| 74 | + break; |
| 75 | + |
| 76 | + default: |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + return exits.success({ |
| 81 | + footprint: footprint |
| 82 | + }); |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | +}; |
0 commit comments