tachyon 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77f52369d61841d8260f1d964ca268d8cf448844
4
- data.tar.gz: dc2c8b41b22e17fff55d2c604e9890ef904c02fa
3
+ metadata.gz: a99e7af845eb71839bb8ea359d658ea027e1b260
4
+ data.tar.gz: 21cf9fa3a7cb668ecbef0c8045b2e4b61c5e089f
5
5
  SHA512:
6
- metadata.gz: 41fb8d56a0c6ca6762f74ed9a4fbe5f96923f857e4ef6229dd53e8bad7f5df23474b1729030700fc31abbeaa21b1a54d09425deb07d57493a832ca5dddfbad40
7
- data.tar.gz: 92c1668f3acd7e7d975faaedcef6f965e3a925cca9e5c171e25a8a932e413059c0758065d05ce2fd47b9ebe9af6654175530bad2e541788aa6e707b428662e74
6
+ metadata.gz: be59050806901dab5b6c6a92d2fe8b1c444d38bcff2a622b43a44742d5ab4ee89786c61803e661ab0519f8a808fc4f63183f030490ab9bfc3289ff9aea3f761b
7
+ data.tar.gz: 39b87a3eb721882aa46a10e5728ac3412bcb1ec67db7b93e91d1810cb935dbdcbaf4974abd4b7341dd1edee174fc7861afb13f111c7752ff4a05c1c4ccc6faa1
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ *.gem
14
+ .DS_Store
data/README.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Tachyon
2
2
 
3
+ Tachyon is a simple library designed to insert rows into any DB managed by ActiveRecord as fast as possible. Tachyon does not do validations. Tachyon does not throw errors on duplicate keys. Tachyon simply gets records into the DB as fast as possible. This is very useful in the case when you need to bulk-insert data for some reason, but it really shouldn't be used to replace your normal ActiveRecord DB operations.
4
+
5
+ Tachyon is roughly as fast as executing raw SQL statements, but with a much more readable syntax. Tachyon uses Arel to geneate the SQL statements and to manage type-casting, this helps to avoid the fragility that can come with manually generating SQL.
6
+
7
+ ## How fast is it?
8
+
9
+ The goal is to be roughly as fast as executing raw SQL via `ActiveRecord::Base.connection`. Tachyon still falls a little short of this mark, but future optimizations will close the gap.
10
+
11
+ ```
12
+ Benchmark Results (inserting 5,000 rows):
13
+ -------------------------------------------
14
+ User.create() : 4.461711 secs
15
+ Raw SQL : 0.597918 secs
16
+ Tachyon.insert(User, Hash) : 1.127233 secs
17
+ Tachyon.insert(User, Array) : 1.078880 secs
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ To insert a single row, simply supply the model class along with a hash of attributes:
23
+
24
+ ```ruby
25
+ Tachyon.insert(Article, id: 13, title: "Brand new article")
26
+ ```
27
+
28
+ To do a bulk insert, supply the model class and an array of attribute hashes. Tachyon will wrap multiple inserts in a transaction for an extra speed boost:
29
+
30
+ ```ruby
31
+ Tachyon.insert(Comment, [
32
+ {id: 1, article_id: 34, title: "Super comment"},
33
+ {id: 2, article_id: 12, title: "Another one"},
34
+ {id: 3, article_id: 90, title: "Comment duex"},
35
+ ])
36
+ ```
3
37
 
4
38
 
5
39
  ## Installation
@@ -18,17 +52,7 @@ Or install it yourself as:
18
52
 
19
53
  $ gem install tachyon
20
54
 
21
- ## Usage
22
-
23
- ```ruby
24
- Tachyon.insert(Article, id: 13, title: "Brand new article")
25
55
 
26
- Tachyon.insert(Comment, [
27
- {id: 1, article_id: 34, title: "Super comment"},
28
- {id: 2, article_id: 12, title: "Another one"},
29
- {id: 3, article_id: 90, title: "Comment duex"},
30
- ])
31
- ```
32
56
 
33
57
  ## License
34
58
 
data/lib/tachyon.rb CHANGED
@@ -13,8 +13,10 @@ class Tachyon
13
13
  end
14
14
 
15
15
  def self.insert_record(klass, data)
16
- defaults = { created_at: Time.now, updated_at: Time.now }
17
- data = defaults.merge(data)
16
+ if klass.has_attribute?(:created_at) && klass.has_attribute?(:updated_at)
17
+ defaults = { created_at: Time.now, updated_at: Time.now }
18
+ data = defaults.merge(data)
19
+ end
18
20
 
19
21
  table = klass.arel_table
20
22
  mapped_data = data.map do |key, value|
@@ -1,3 +1,3 @@
1
1
  class Tachyon
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tachyon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Gough