New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

async_record

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async_record

  • 0.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= AsyncRecord

One of the greatest things about running on an event-based server is that you can get accelerated performance in database access.

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.

NOTE: Even though your connections are non-blocking to the database server, the database server is still blocking when accessing IO (disk/memory).

To use AsyncRecord, do the following:

Install the Gem:

sudo gem install async_record

Setup async_record:

require 'async_record' conn = AsyncRecord::Connection::MySQL.new(:host => "127.0.0.1", :port => 3306, :user => "root", :database => "database") conn.connect

Define a model:

class User < AsyncRecord::Base set_table_name "users" end

=== Controller

These examples are for the Fastr web framework.

In your controller, try the following (remember to put the following in a deferred response):

=== Get all the rows in the table:

User.all(:limit => 256) do |users| users.each do |user| response.send_data("#{user.username}\n") end response.succeed end

=== Find a row by ID

User.find(1) do |user| if user.nil? response.send_data("User not found") else response.send_data("User: #{user.username}\n") end response.succeed end

=== Get the count of rows in the table

User.count do |count| response.send_data("Count: #{count}") response.succeed end

=== Run a custom query

User.query("select username from users") do |results| response.send_data("Results: #{results.inspect}") response.succeed end

WARNING: AsyncRecord is under heavy development, but its pretty cool :).

FAQs

Package last updated on 26 Jun 2010

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc