Permalink
Browse files

move all the models into individual files

  • Loading branch information...
1 parent d2a9251 commit 2834c10e4ddf4b659f8828801707f23ab35dbf33 @leafo leafo committed Feb 27, 2014
View
@@ -11,6 +11,8 @@ bucket = require "storage_bucket"
persist = require "ext.luarocks.persist"
+math.randomseed os.time!
+
import
respond_to
capture_errors
@@ -38,9 +40,10 @@ import
Manifests
ManifestModules
ApiKeys
- get_all_pages
from require "models"
+import get_all_pages from require "helpers.models"
+
import concat, insert from table
parse_rockspec = (text) ->
View
@@ -0,0 +1 @@
+include_rules
View
@@ -0,0 +1,42 @@
+
+db = require "lapis.db"
+import insert from table
+
+increment_counter = (keys, amount=1) =>
+ amount = tonumber amount
+ keys = {keys} unless type(keys) == "table"
+
+ update = {}
+ for key in *keys
+ update[key] = db.raw"#{db.escape_identifier key} + #{amount}"
+
+ db.update @@table_name!, update, @_primary_cond!
+
+generate_key = do
+ import random from math
+ random_char = ->
+ switch random 1,3
+ when 1
+ random 65, 90
+ when 2
+ random 97, 122
+ when 3
+ random 48, 57
+
+ (length) ->
+ string.char unpack [ random_char! for i=1,length ]
+
+get_all_pages = (pager) ->
+ i = 1
+ accum = {}
+ while true
+ items = pager\get_page i
+ break unless next items
+ for item in *items
+ insert accum, item
+ i += 1
+
+ accum
+
+
+{ :increment_counter, :generate_key, :get_all_pages }
Oops, something went wrong.

0 comments on commit 2834c10

Please sign in to comment.