tachyon 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/tachyon.rb +5 -20
- data/lib/tachyon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db6f4578207aa4b25e06152c93a369b29d79fc7a
|
4
|
+
data.tar.gz: 431b5c7716146543006df3512afd0b9711b90d7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 869ee5138af1793a61f815f736090f47aed7e7e2a963fede0ae9cff83f3df5ca93701c5259ed0edb8bd94d2bd8aea34e2111894d851dfc145783d0674283caef
|
7
|
+
data.tar.gz: c02c436b099bc994343c24f529a4eb52fc5d2da8610e1bb0b7e82f87c9c338363c057c476cbae6a81e55e2ba00b71a7c6963c73732c23021b4736c6b41c56aef
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
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, and only does minimal
|
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, and only does minimal typecasting. 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
4
|
|
5
5
|
An ideal use-case for Tachyon (and the reason it was developed) is to dump/insert data from the DB as part of the setup step for large test cases.
|
6
6
|
|
@@ -34,7 +34,7 @@ Tachyon does extremely minimal typecasting. Integers and Floats are passed throu
|
|
34
34
|
|
35
35
|
## Usage
|
36
36
|
|
37
|
-
To insert simply supply the model class along with a hash of attributes
|
37
|
+
To insert simply supply the model class along with a hash of attributes:
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
Tachyon.insert(Article, id: 13, title: "Brand new article")
|
data/lib/tachyon.rb
CHANGED
@@ -3,7 +3,6 @@ require "tachyon/version"
|
|
3
3
|
class Tachyon
|
4
4
|
class << self
|
5
5
|
|
6
|
-
@@sql_cache = {}
|
7
6
|
@@connection_cache = {}
|
8
7
|
|
9
8
|
def insert(klass, data)
|
@@ -18,28 +17,14 @@ class Tachyon
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def sql_for(klass, data)
|
21
|
-
|
22
|
-
|
23
|
-
raise "Data was not supplied for all columns - " + e.to_s
|
24
|
-
end
|
25
|
-
|
26
|
-
def sql_template_for(klass)
|
27
|
-
return @@sql_cache[klass] if @@sql_cache.has_key?(klass)
|
28
|
-
|
29
|
-
columns = klass.columns.map(&:name)
|
30
|
-
table_name = klass.table_name
|
31
|
-
columns_string = columns.map {|x| "`#{x}`" }.join(", ")
|
32
|
-
values_string = columns.map {|x| "%{#{x}}" }.join(", ")
|
20
|
+
columns = "`" + data.keys.join("`, `") + "`"
|
21
|
+
values = quote_data(data.values).join(", ")
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
@@sql_cache[klass] = sql
|
23
|
+
"INSERT INTO `#{klass.table_name}` (#{columns}) VALUES (#{values})"
|
37
24
|
end
|
38
25
|
|
39
26
|
def quote_data(data)
|
40
|
-
data.map
|
41
|
-
[key, quote_value(value)]
|
42
|
-
end.to_h
|
27
|
+
data.map {|value| quote_value(value) }
|
43
28
|
end
|
44
29
|
|
45
30
|
def quote_value(value)
|
@@ -65,6 +50,6 @@ class Tachyon
|
|
65
50
|
else attribute
|
66
51
|
end
|
67
52
|
end
|
68
|
-
|
53
|
+
|
69
54
|
end
|
70
55
|
end
|
data/lib/tachyon/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tachyon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Gough
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|