nssql 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +13 -6
- data/lib/nssql/table.rb +33 -15
- data/lib/nssql/version.rb +1 -1
- data/nssql.gemspec +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3800e381c1ae7811f2e0eac2c216d61047d87c06fbc576331d4b787d7c554388
|
4
|
+
data.tar.gz: 991f4188a0a767ac2714157a5deaca48e2c2edd26c1235a1397c40b52a7e5a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae877bc33608e7153a87f78c87a0abd2e5bf921be54c14b0186f0ae309c09bf33b4a1f49883f2b67a2bf9f4e1825d4371d35b261f802bf85499c5e402b949376
|
7
|
+
data.tar.gz: f8e03add922fcd156a184308392aa40125416b7e31d9a3c03129b6b0d61a33c7ca8d57a158bff1a1b2184f266c2c59959c6e847b79d2f1cacb90e45fbc68de7c
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.6.
|
1
|
+
ruby-2.6.3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -39,16 +39,23 @@ end
|
|
39
39
|
### Table
|
40
40
|
|
41
41
|
```ruby
|
42
|
-
class TestTable
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
class TestTable
|
43
|
+
include NSSQL::Table
|
44
|
+
|
45
|
+
ns_table_name :test_table
|
46
|
+
ns_primary_keys :id, :line_id
|
47
|
+
ns_column :id
|
48
|
+
ns_column :line_id
|
49
|
+
ns_column :name, as: :display_name
|
46
50
|
end
|
51
|
+
|
52
|
+
TestTable.ns_column_names # => [:id, :line_id, :name]
|
53
|
+
TestTable.ns_aliased_column_names # => [:id, :line_id, :display_name]
|
47
54
|
```
|
48
55
|
|
49
56
|
### Select columns
|
50
57
|
|
51
|
-
`TestTable.
|
58
|
+
`TestTable.select_ns_columns_query` will generate:
|
52
59
|
|
53
60
|
```SQL
|
54
61
|
SELECT
|
@@ -59,7 +66,7 @@ ORDER BY
|
|
59
66
|
id
|
60
67
|
```
|
61
68
|
|
62
|
-
We can pass options, like `TestTable.
|
69
|
+
We can pass options, like `TestTable.select_ns_columns_query(where: 'id > 500')` and this will generate:
|
63
70
|
|
64
71
|
```SQL
|
65
72
|
SELECT
|
data/lib/nssql/table.rb
CHANGED
@@ -3,38 +3,56 @@
|
|
3
3
|
module NSSQL
|
4
4
|
# Base class for representing NetSuite tables.
|
5
5
|
# Table name, primary keys and wanted columns are expected to be defined.
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
#
|
7
|
+
module Table
|
8
|
+
def self.included(klass)
|
9
|
+
klass.extend(ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Class methods for NSSQL::Table module.
|
13
|
+
#
|
14
|
+
module ClassMethods
|
15
|
+
attr_reader :ns_columns
|
16
|
+
|
17
|
+
def select_ns_columns_query(where: nil)
|
9
18
|
where_statement = "WHERE #{where}" if where
|
10
19
|
|
11
20
|
<<~SQL
|
12
21
|
SELECT
|
13
|
-
#{
|
22
|
+
#{ns_column_names.join(',')}
|
14
23
|
FROM
|
15
|
-
#{
|
24
|
+
#{ns_table_name}
|
16
25
|
#{where_statement if where}
|
17
26
|
ORDER BY
|
18
|
-
#{
|
27
|
+
#{ns_primary_keys.first}
|
19
28
|
SQL
|
20
29
|
end
|
21
30
|
|
22
|
-
def
|
23
|
-
return @
|
31
|
+
def ns_table_name(ns_table_name = nil)
|
32
|
+
return @ns_table_name if ns_table_name.nil?
|
24
33
|
|
25
|
-
@
|
34
|
+
@ns_table_name = ns_table_name
|
26
35
|
end
|
27
36
|
|
28
|
-
def
|
29
|
-
return @
|
37
|
+
def ns_primary_keys(*ns_primary_keys)
|
38
|
+
return @ns_primary_keys if ns_primary_keys.empty?
|
30
39
|
|
31
|
-
@
|
40
|
+
@ns_primary_keys = ns_primary_keys.flatten
|
32
41
|
end
|
33
42
|
|
34
|
-
def
|
35
|
-
|
43
|
+
def ns_column(name, options = {})
|
44
|
+
@ns_columns ||= {}
|
45
|
+
@ns_columns[name] = options
|
46
|
+
end
|
47
|
+
|
48
|
+
def ns_aliased_column_names
|
49
|
+
ns_columns.sort.map do |name, options|
|
50
|
+
options[:as] || name
|
51
|
+
end
|
52
|
+
end
|
36
53
|
|
37
|
-
|
54
|
+
def ns_column_names
|
55
|
+
ns_columns.keys.sort
|
38
56
|
end
|
39
57
|
end
|
40
58
|
end
|
data/lib/nssql/version.rb
CHANGED
data/nssql.gemspec
CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
39
39
|
|
40
40
|
spec.add_runtime_dependency 'ruby-odbc', '~> 0.99997'
|
41
41
|
|
42
|
-
spec.add_development_dependency 'bundler', '
|
42
|
+
spec.add_development_dependency 'bundler', '>= 1.17', '< 3'
|
43
43
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
44
44
|
spec.add_development_dependency 'rake', '~> 10.0'
|
45
45
|
spec.add_development_dependency 'rubocop', '>= 0.60.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nssql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Love Ottosson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-odbc
|
@@ -28,16 +28,22 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.17'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3'
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '1.17'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '3'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: minitest
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
149
|
- !ruby/object:Gem::Version
|
144
150
|
version: '0'
|
145
151
|
requirements: []
|
146
|
-
rubygems_version: 3.0.
|
152
|
+
rubygems_version: 3.0.4
|
147
153
|
signing_key:
|
148
154
|
specification_version: 4
|
149
155
|
summary: Lightweight gem for fetching data from NetSuite with SQL.
|