tachyon 0.2.0 → 0.2.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: 020224e8c886048d69c0c929aa937d2bb6939dff
4
- data.tar.gz: bc97180405d1c796355ab0d4fcec8bcefdd43d6b
3
+ metadata.gz: db6f4578207aa4b25e06152c93a369b29d79fc7a
4
+ data.tar.gz: 431b5c7716146543006df3512afd0b9711b90d7a
5
5
  SHA512:
6
- metadata.gz: 1ab76163499e5b2407e07a6f71d4cc2630bb46fcdaa9b4cae843f4480068cdfbcd526ccb4b79946726d1150a08f42674270b9f02753d0a16fc511dc516fca4ac
7
- data.tar.gz: d34249d947078919f4c76b74ac0cda7bf7ab0d5005fb3b1bd47be35643d8b7c99a1e142c6976808ad70ecf1dde5378e95e08ec285bef00cfa3251181e0677dba
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 typescasting. 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.
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. It's important to note that the keys of the hash must be symbols, not strings:
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")
@@ -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
- sql_template_for(klass) % quote_data(data)
22
- rescue KeyError => e
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
- sql = "INSERT INTO `#{table_name}` (#{columns_string}) VALUES (#{values_string})"
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 do |key, value|
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
@@ -1,3 +1,3 @@
1
1
  class Tachyon
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-17 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler