async_record 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +63 -13
- data/Rakefile +1 -0
- data/VERSION +1 -1
- metadata +17 -3
data/README.rdoc
CHANGED
@@ -1,17 +1,67 @@
|
|
1
|
-
=
|
1
|
+
= AsyncRecord
|
2
2
|
|
3
|
-
|
3
|
+
One of the greatest things about running on an event-based server is that you can get accelerated performance in database access.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
-
* Send me a pull request. Bonus points for topic branches.
|
5
|
+
Usually there is a lot of time spent blocking for a database query to return. In AsyncRecord, your queries don't block the request. You will receive a callback once the query has completed. This has major performance implications.
|
14
6
|
|
15
|
-
|
7
|
+
NOTE: Even though your connections are non-blocking to the database server, the database server is still blocking when accessing IO (disk/memory).
|
16
8
|
|
17
|
-
|
9
|
+
To use AsyncRecord, do the following:
|
10
|
+
|
11
|
+
Install the Gem:
|
12
|
+
|
13
|
+
sudo gem install async_record
|
14
|
+
|
15
|
+
Setup async_record:
|
16
|
+
|
17
|
+
require 'async_record'
|
18
|
+
conn = AsyncRecord::Connection::MySQL.new(:host => "127.0.0.1", :port => 3306, :user => "root", :database => "database")
|
19
|
+
conn.connect
|
20
|
+
|
21
|
+
Define a model:
|
22
|
+
|
23
|
+
class User < AsyncRecord::Base
|
24
|
+
set_table_name "users"
|
25
|
+
end
|
26
|
+
|
27
|
+
=== Controller
|
28
|
+
|
29
|
+
These examples are for the Fastr web framework.
|
30
|
+
|
31
|
+
In your controller, try the following (remember to put the following in a deferred response):
|
32
|
+
|
33
|
+
=== Get all the rows in the table:
|
34
|
+
|
35
|
+
User.all(:limit => 256) do |users|
|
36
|
+
users.each do |user|
|
37
|
+
response.send_data("#{user.username}\n")
|
38
|
+
end
|
39
|
+
response.succeed
|
40
|
+
end
|
41
|
+
|
42
|
+
=== Find a row by ID
|
43
|
+
|
44
|
+
User.find(1) do |user|
|
45
|
+
if user.nil?
|
46
|
+
response.send_data("User not found")
|
47
|
+
else
|
48
|
+
response.send_data("User: #{user.username}\n")
|
49
|
+
end
|
50
|
+
response.succeed
|
51
|
+
end
|
52
|
+
|
53
|
+
=== Get the count of rows in the table
|
54
|
+
|
55
|
+
User.count do |count|
|
56
|
+
response.send_data("Count: #{count}")
|
57
|
+
response.succeed
|
58
|
+
end
|
59
|
+
|
60
|
+
=== Run a custom query
|
61
|
+
|
62
|
+
User.query("select username from users") do |results|
|
63
|
+
response.send_data("Results: #{results.inspect}")
|
64
|
+
response.succeed
|
65
|
+
end
|
66
|
+
|
67
|
+
WARNING: AsyncRecord is under heavy development, but its pretty cool :).
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/chrismoos/async_record"
|
12
12
|
gem.authors = ["Chris Moos"]
|
13
13
|
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
gem.add_dependency "em-mysql"
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
16
|
end
|
16
17
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Chris Moos
|
@@ -32,6 +32,20 @@ dependencies:
|
|
32
32
|
version: "0"
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: em-mysql
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
35
49
|
description: Asynchronous ORM for Ruby
|
36
50
|
email: chris@tech9computers.com
|
37
51
|
executables: []
|