catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Table left outer join #618

Closed StefansArya closed 6 years ago

StefansArya commented 7 years ago

Hi, Can you implement LEFT OUTER JOIN for the select API? If a table doesn't contain related id, it will return null instead of empty string..

users

| user_id | username      |
| 123     | myusername    |
| 126     | otherusername |

data

| user_id | realname    |
| 126     | otherperson |

Example 1 SELECT "data"."realname","users"."user_id" FROM "users" LEFT OUTER JOIN "data" ON "users"."user_id" = "data"."user_id" WHERE "users"."username" = 'myusername'

Expected output

[
    ["realname"=>null, "user_id"=>123]
]

Example 2 SELECT "data"."realname","users"."user_id" FROM "users" LEFT OUTER JOIN "data" ON "users"."user_id" = "data"."user_id" WHERE "users"."username" = 'otherusername'

Expected output

[
    ["realname"=>"otherperson", "user_id"=>126]
]
StefansArya commented 7 years ago

Add on this line

Andrews54757 commented 7 years ago

@StefansArya What would be the key? <>, ><, >, and < are already taken.

Also, you would also have to edit

https://github.com/catfan/Medoo/blob/6798b9698ee60ee98a4d342485904322922b2b3b/src/Medoo.php#L835

StefansArya commented 7 years ago

Maybe >~

The regex will be (\[(?<join>\<|\>|\>\<|\<\>|\>\~)\])?(?<table>[a-zA-Z0-9_]+)\s?(\((?<alias>[a-zA-Z0-9_]+)\))?

Andrews54757 commented 7 years ago

@StefansArya Okay then, make a pull request. Catfan then can merge it later

catfan commented 7 years ago

@Andrews54757 @StefansArya No. This feature is acceptable, but please don't make a pull request. We can not make a final syntax decision from now. Need time to think around.

StefansArya commented 7 years ago

@catfan Yeah, I know that I don't need to create pull request. I already feel it when I dive into your library.. Anyway, thanks for your time!

Andrews54757 commented 7 years ago

@catfan I suggest using the PEAR format. It nice and clean, and its easy

catfan commented 7 years ago

I checked out the manual. The LEFT JOIN is the same as LEFT OUTER JOIN. So, it don't need to implement the OUTER as option.

https://dev.mysql.com/doc/refman/5.7/en/join.html