sailorproject / sailor

A Lua MVC Web Framework.
MIT License
921 stars 125 forks source link

Suggestion: model.find with ? and :params #124

Open limadm opened 8 years ago

limadm commented 8 years ago

Hello!

First, congratulations for this project! I saw it in a LuaConf this year and it's seems really promising, so I adopted it for developing new applications, so I can work to help it grow fast, stable and friendly.

Now on the issue: I implemented a separate model.query in my fork to be able to do this:

local params = {
  device = Device:query('num_points is not null LIMIT 1'),
  points = {}
}
for p in Point:query {
  '(name like ? OR description like ?) AND size < :size LIMIT 10',
  name, desc,
  size = params.device.size
} do
  table.insert(params.points, p)
end
page:render('view', params)

In the process I saw a comment that model.find* should support and escape parameterized attributes, so I think my implementation suits this task. But before adopting this change, couldn't we make a more general model query syntax to suit both SQL and NoSQL ORM (e.g. tarantool, a luajit nosql db)? A setup with openresty and tarantool is really challenging to beat, performance-wise. What you think? =]

Etiene commented 8 years ago

Sorry for taking long to reply to this issue! I was finishing my master thesis!

There is another issue concerning db queries that was open more recently by @CriztianiX. Maybe we should make a joint effort on refactoring how the db module works for a 1.0 release!

Alternatively, there is a student from India from Rails Girls Summer of Code that was interested in contributing and making a sailor-redis integration. What do you think? We could devise some goals, include tarantool and share the effort :)

I'll have a two month vacation between graduating and starting a job, I really want to get some interesting things done here :D

CriztianiX commented 8 years ago

127

CriztianiX commented 8 years ago

I'm refactoring the db layer (just playing) and you can check it in my brach I've added a new "interpolate query" function

https://github.com/CriztianiX/sailor/tree/ref_db

Etiene commented 7 years ago

Cool! I really like the code you're putting there! Wow, resty-postgres as well! That's awesome! Please don't forget to take a look at these commit message messages guidelines for the next commits: https://github.com/sailorproject/sailor/blob/master/CONTRIBUTING.md#commit-message