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 +4 -4
- data/.gitignore +2 -0
- data/README.md +34 -10
- data/lib/tachyon.rb +4 -2
- data/lib/tachyon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a99e7af845eb71839bb8ea359d658ea027e1b260
|
4
|
+
data.tar.gz: 21cf9fa3a7cb668ecbef0c8045b2e4b61c5e089f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be59050806901dab5b6c6a92d2fe8b1c444d38bcff2a622b43a44742d5ab4ee89786c61803e661ab0519f8a808fc4f63183f030490ab9bfc3289ff9aea3f761b
|
7
|
+
data.tar.gz: 39b87a3eb721882aa46a10e5728ac3412bcb1ec67db7b93e91d1810cb935dbdcbaf4974abd4b7341dd1edee174fc7861afb13f111c7752ff4a05c1c4ccc6faa1
|
data/.gitignore
CHANGED
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
|
-
|
17
|
-
|
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|
|
data/lib/tachyon/version.rb
CHANGED