Skip to content

Commit

Permalink
we can insert messages
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed May 25, 2011
1 parent 51a12fe commit b189b11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/backends/sqlite.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class Backend
@db = new Sqlite3.Database options.path || ':memory:'
@setup()

push: (msg) ->
@db.run "INSERT INTO messages VALUES (?)", msg.toString()

# Gets the earliest message.
peek: (cb) ->
sql = "SELECT rowid AS id, data FROM messages ORDER BY rowid LIMIT 1"
Expand Down
16 changes: 12 additions & 4 deletions test/sqlite_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ calls = 0

# no messages
backend.peek (err, obj) ->
calls += 1
assert.equal null, err
assert.equal null, obj
calls += 1
assert.equal null, err
assert.equal null, obj

backend.push "booya"

backend.peek (err, obj) ->
calls += 1
assert.equal null, err
assert.ok obj.id
assert.equal "booya", obj.data

process.on 'exit', ->
assert.equal 1, calls
assert.equal 2, calls

0 comments on commit b189b11

Please sign in to comment.