Created
March 29, 2012 17:17
-
-
Save doug-martin/2240190 to your computer and use it in GitHub Desktop.
Patio orm join example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var patio = require("patio"), | |
SQL = patio.sql; | |
var DB = patio.connect("mysql://localhost:3306/test"); | |
var sql = "SELECT * FROM Device AS dev JOIN PushID AS pid ON dev.macAddress=pid.idDevice JOIN State AS state ON pid.deviceToken=state.pushId JOIN Message AS msg ON state.messageId=msg.idMessage WHERE dev.macAddress={macAddress} AND msg.idMessage={idMessage}"; | |
var sqlDs = DB.fetch(sql, {macAddress:"", idMessage:"idMessage"}); | |
console.log(sqlDs.sql); | |
sqlDs.all().then(function (res) { | |
console.log(res); | |
}, function (err) { | |
console.log(err); | |
}) | |
//OR | |
var macAddress = "9d:76:13:99:g3:4c", idMessage = "xxxxx" | |
var ds = DB.from("Device") | |
.join("PushId", {macAddress:SQL.idDevice}) | |
.join("State", {deviceToken:SQL.pushId}) | |
.join("Message", {messageId:SQL.idMessage}); | |
console.log(ds.where({Device__macAddress:macAddress, Message__idAddress:idMessage}).sql); | |
ds.where({Device__macAddress:macAddress, Message__idAddress:idMessage}).all().then(function (res) { | |
console.log(res); | |
}, function (err) { | |
console.log(err); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment