lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I do provide a simple code structure to my teammates so they can focus on the db logic:

 

```

local ctx = MyDatabase()

 

with(ctx)(function()

local entity = ctx.Users:Add{ name = form.name }

entity.create = Date.Now

ctx:SaveChanges()

 

self:Redirect(“/user/profile/” .. entity.id)

end, function(err)

    self:Redirect(“/user/logout”)

end)

```

 

The “with” can have several objects with Open/Close method, so they can be called at the start and the end point. The second function is the error handler, if it’s omit, the “error” will be used so it can be handled by the global error handler.