[go: up one dir, main page]

[db] Add join tables to Fluid SQL builder

For example (queries for MySQL):

// Same column "id" in both the tables:
db.table(one).join(two, [id]).get()
// SELECT * FROM one JOIN two USING(id);

// Different column name:
db.table(one).join(two, [ id1 : "id2" ], LEFT).get()
// SELECT * FROM one LEFT JOIN two ON(one.id1 = two.id2);

// Multiple conditions:
db.table(one).join(two, [ 
   [ id ], // Same in both
   [ user1 : "user2" ],
   [ date1 : "date2" ]
], RIGHT).get()
// SELECT * FROM one RIGHT JOIN two 
//     ON(one.id = two.id 
//    AND one.user1 = two.user2
//    AND one.date1 = two.date2);

Multiple tables:

db.table(one)
  .join(two, [ id2 : "id1" ], LEFT)
  .join(three, [ date3 : "one.date1" ], RIGHT)
  .get()
// SELECT * FROM one 
//     LEFT JOIN two ON(two.id2 = one.id1)
//    RIGHT JOIN three ON(three.date3 = one.date1)
Edited by A.Lepe
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information