Skip to content

Instantly share code, notes, and snippets.

@bigeasy
Created October 14, 2010 23:02
Show Gist options
  • Select an option

  • Save bigeasy/627244 to your computer and use it in GitHub Desktop.

Select an option

Save bigeasy/627244 to your computer and use it in GitHub Desktop.
MySQL Utilities
fs = require "fs"
Client = require("mysql").Client
createClient = ->
client = new Client()
client.user = "user"
client.password = "password"
client.database = "database"
client
select = (query, parameters, callback) ->
client = createClient()
client.connect ->
client.query query, parameters, (error, results, fields) ->
throw error if error
callback results, fields
client.end()
queries = {}
for file in fs.readdirSync __dirname + "/../queries"
queries[file] = fs.readFileSync __dirname + "/../queries/" + file , "utf8"
<% @select @queries.orders, [ @cusomterId ], (results) -> : %>
<% for order in results: %>
<div>Order Id: <%= order.id %></div>
<% @select @queries.orderItems, [ order.id ], (results) -> : %>
<% for item in results: %>
<p><%= item.quantity %> of <%= item.productDescription %></p>
<% end %>
<% end %>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment