Git Product home page Git Product logo

Comments (8)

acarl005 avatar acarl005 commented on June 15, 2024 1

You can manually add a where function to filter out the rows with NULL values at that column.

I'm going to make a patch to do a null check before attempting to call toSQL inside the function so that it does not throw an exception.

from join-monster.

acarl005 avatar acarl005 commented on June 15, 2024

Yes this is possible. Just add a where function beside the sqlBatch.

sqlBatch: {
  // which column to match up to the users
  thisKey: 'post_id',
  // the other column to compare to
  parentKey: 'id'
},
where: function(table) {
  return `${table}."xyz" = 8989`
}

from join-monster.

praseedasathaye avatar praseedasathaye commented on June 15, 2024

How do I get the parent (User) type's argument (xyz)? In below code it gives args.id comes as "undefined".

where: (table, args, context) => { 
        return `${table}.invoice_id = ${args.id}`
      }

from join-monster.

acarl005 avatar acarl005 commented on June 15, 2024

Oh I see. Currently, Join Monster does not provide the arguments from a parent field. I'll consider adding that to the callback signature.

For now, you'll have to repeat the argument on the posts field.

{
  user(xyz: 8989) {
    fullName
    email
    posts(xyz: 8989) {
      id
      body
      comments {
        id
        body
        author {
          id
          fullName
        }
      }
    }
  }
}

from join-monster.

praseedasathaye avatar praseedasathaye commented on June 15, 2024

I see. Then as a workaround can I use sqlJoin with sqlBatch for satisfying multiple conditions like below? Basically I want the child to form a batch query using multiple conditions.

comments: {
......
sqlJoin: (postTable, commentsTable) => `${postTable}.XYZ = ${commentsTable}.XYZ`
sqlBatch: {
    // which column to match up to the users
    thisKey: 'post_id',
    // the other column to compare to
    parentKey: 'id'
 }
...
}

which need to result like this:

SELECT
  "comments"."id" AS "id",
  "comments"."body" AS "body",
  "comments"."post_id" AS "post_id"
FROM comments AS "comments"
LEFT JOIN posts AS "posts" ON "comments".XYZ = "posts".XYZ
WHERE "comments"."post_id" IN (2,8,11,12)

from join-monster.

acarl005 avatar acarl005 commented on June 15, 2024

Unfortunately not. When using sqlBatch, a separate query is made, so you do not have access to any values from the users or posts except for the parentKey specified in sqlBatch. You cannot mix sqlJoin with sqlBatch.

Another option is to simply use joins all the way through. So you can replace sqlBatch with sqlJoin.

from join-monster.

praseedasathaye avatar praseedasathaye commented on June 15, 2024

ok. Related to sqlBatch, can I put condition to join only when the column value is not null? I get the below error as the column I use in sqlBatch is null for some of the rows. In below case PO_DISTRIBUTION_ID is null which I am using in sqlBatch join.

  { INVOICE_ID: 168295,
    INVOICE_NUM: 'ERS-8928-64',
    INVOICE_AMOUNT: 109.88,
    INVOICE_CURRENCY_CODE: 'USD',
    batch__BATCH_ID: 22115,
    batch__BATCH_NAME: 'ERS:101',
    batch__BATCH_DATE: 2012-05-30T08:00:00.000Z,
    batch__LAST_UPDATED_BY: 'WHSE_MGR_M1',
    batch__CREATED_BY: 'WHSE_MGR_M1',
    'lines__INVOICE_ID#LINE_NUMBER': '1682955',
    lines__LINE_NUMBER: 5,
    lines__LINE_TYPE_LOOKUP_CODE: 'TAX',
    lines__AMOUNT: 4,
    lines__PO_DISTRIBUTION_ID: null },
   ........ +106ms
  join-monster 5 rows... +0ms
{ TypeError: Cannot read property 'toSQL' of null
    at maybeQuote (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/util.js:95:19)
    at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:52:45
    at Array.map (native)
    at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:51:57
    at Generator.next (<anonymous>)
    at step (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:191)
    at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:437
    at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:99
    at Promise.all.sqlAST.children.map (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:109:22)
    at Array.map (native)
    at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:34:40
    at Generator.next (<anonymous>)
    at step (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:191)
    at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:437
    at /Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:19:99
    at nextBatch (/Users/Praseeda/Projects/join-monster-demo/node_modules/join-monster/dist/batchPlanner.js:115:17)
  message: 'Cannot read property \'toSQL\' of null',

from join-monster.

praseedasathaye avatar praseedasathaye commented on June 15, 2024

Thanks.

from join-monster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.