micro_sql 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -4,12 +4,16 @@ require "json"
4
4
 
5
5
  class MicroSql::KeyValueTable < MicroSql::Table
6
6
  def initialize(db, table_name = "settings")
7
- super db, "CREATE TABLE #{table_name}(uid TEXT PRIMARY KEY, value TEXT, ttl BIGINT)"
7
+ super db, "CREATE TABLE #{table_name}(uid TEXT PRIMARY KEY, value TEXT, ttl INTEGER NOT NULL)"
8
8
  end
9
9
 
10
10
  def [](key)
11
11
  value, ttl = db.ask("SELECT value, ttl FROM #{table_name} WHERE uid=?", key)
12
- decode(value) if !ttl || ttl < Time.now.to_i
12
+ decode(value) if ttl && (ttl == 0 || ttl > Time.now.to_i)
13
+ end
14
+
15
+ def delete_all
16
+ @db.exec "DELETE FROM #{table_name}"
13
17
  end
14
18
 
15
19
  def cached(key, ttl = nil, &block)
@@ -19,7 +23,7 @@ class MicroSql::KeyValueTable < MicroSql::Table
19
23
  def update(key, value, ttl = nil)
20
24
  if value
21
25
  encoded = encode(value)
22
- ttl += Time.now.to_i if ttl
26
+ ttl = ttl ? ttl + Time.now.to_i : 0
23
27
  affected = @db.ask("UPDATE #{table_name} SET value=?, ttl=? WHERE uid=?", encoded, ttl, key)
24
28
  if affected == 0
25
29
  @db.ask("INSERT INTO #{table_name}(value, ttl, uid) VALUES(?,?,?)", encoded, ttl, key)
@@ -31,6 +35,11 @@ class MicroSql::KeyValueTable < MicroSql::Table
31
35
  value
32
36
  end
33
37
 
38
+ def expire(key, ttl)
39
+ ttl = ttl ? ttl + Time.now.to_i : ttl
40
+ @db.ask("UPDATE #{table_name} SET ttl=? WHERE uid=?", ttl, key)
41
+ end
42
+
34
43
  alias :[]= :update
35
44
 
36
45
  private
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "micro_sql"
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["radiospiel"]
12
- s.date = "2012-04-03"
12
+ s.date = "2012-04-04"
13
13
  s.description = "You only need a single method to talk to your database..."
14
14
  s.email = "eno@open-lab.org"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-03 00:00:00.000000000 Z
12
+ date: 2012-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
16
- requirement: &70112976340220 !ruby/object:Gem::Requirement
16
+ requirement: &70179126169140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70112976340220
24
+ version_requirements: *70179126169140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70112976338980 !ruby/object:Gem::Requirement
27
+ requirement: &70179126168360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70112976338980
35
+ version_requirements: *70179126168360
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70112976337920 !ruby/object:Gem::Requirement
38
+ requirement: &70179126167420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70112976337920
46
+ version_requirements: *70179126167420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70112976336440 !ruby/object:Gem::Requirement
49
+ requirement: &70179126166660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70112976336440
57
+ version_requirements: *70179126166660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &70112976328460 !ruby/object:Gem::Requirement
60
+ requirement: &70179126165880 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70112976328460
68
+ version_requirements: *70179126165880
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ruby-debug19
71
- requirement: &70112976327360 !ruby/object:Gem::Requirement
71
+ requirement: &70179126165220 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70112976327360
79
+ version_requirements: *70179126165220
80
80
  description: You only need a single method to talk to your database...
81
81
  email: eno@open-lab.org
82
82
  executables: []
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: 2450718260584937907
121
+ hash: -4089216543794682112
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements: