rubylite 0.1.0 → 0.1.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/Gemfile.lock +5 -1
- data/README.md +5 -5
- data/bin/main.rb +2 -2
- data/bin/vbhv.db +0 -0
- data/lib/functions.rb +44 -0
- data/lib/rubylite.rb +59 -3
- data/lib/rubylite/version.rb +2 -2
- data/rubylite.gemspec +2 -1
- data/vbhv.db +0 -0
- metadata +19 -4
- data/lib/module.rb +0 -36
- data/lib/rquery.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 837a37d03c91c250f62f3051e41cb0041513bed5
|
4
|
+
data.tar.gz: 3acddefaaa0491601364518c55805ef577c10fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07664bb79accbc6236b02b8d941ed727764ac4d2714bb4da31e6faca1cd99324eba7fded95a949d8b8f596c2ec6f5185af50c7ba8e22b205d2dfcc173d90ac8b
|
7
|
+
data.tar.gz: 310077619e45e6df668643cbd57ff0be151a245dd3d7bbc556f915c8ad099eb0f97d19450808cb8eeae7c7d80610c7596d30f1a7c2ac721c6563d6b3f81845cb
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubylite (0.1.
|
4
|
+
rubylite (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
amalgalite (1.6.1)
|
10
|
+
arrayfields (~> 4.9)
|
11
|
+
arrayfields (4.9.2)
|
9
12
|
minitest (5.11.3)
|
10
13
|
rake (10.5.0)
|
11
14
|
|
@@ -13,6 +16,7 @@ PLATFORMS
|
|
13
16
|
ruby
|
14
17
|
|
15
18
|
DEPENDENCIES
|
19
|
+
amalgalite (~> 1.6)
|
16
20
|
bundler (~> 1.16)
|
17
21
|
minitest (~> 5.0)
|
18
22
|
rake (~> 10.0)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Rubylite
|
1
|
+
# Rubylite [](https://badge.fury.io/rb/rubylite) [](https://codeclimate.com/github/vbhv007/rubylite/maintainability)
|
2
2
|
|
3
3
|
This is a command line tool which can interact with databases
|
4
4
|
|
@@ -30,9 +30,9 @@ Let's say **users** is a table
|
|
30
30
|
| 1 | 'vbhv' |
|
31
31
|
| 2 | 'luci' |
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
User.first # 1 vbhv
|
34
|
+
User.last # 2 luci
|
35
|
+
User.find_by('name', 'vbhv') # 1 vbhv
|
36
36
|
```
|
37
37
|
|
38
38
|
## Development
|
@@ -43,7 +43,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
43
43
|
|
44
44
|
## Contributing
|
45
45
|
|
46
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
46
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vbhv007/rubylite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
47
47
|
|
48
48
|
## License
|
49
49
|
|
data/bin/main.rb
CHANGED
data/bin/vbhv.db
ADDED
Binary file
|
data/lib/functions.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'amalgalite'
|
2
|
+
# this is Functions
|
3
|
+
module Functions
|
4
|
+
def exe(query)
|
5
|
+
Rubylite.new.exec_this(@database, query)
|
6
|
+
end
|
7
|
+
|
8
|
+
def find_table_name
|
9
|
+
(to_s + 's').downcase
|
10
|
+
end
|
11
|
+
|
12
|
+
def first(arg = 1)
|
13
|
+
exe("select * from #{find_table_name} order by
|
14
|
+
#{find_table_name}.id ASC limit #{arg}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def take(arg = 1)
|
18
|
+
exe("select * from #{find_table_name} limit #{arg}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def last(arg = 1)
|
22
|
+
exe("select * from #{find_table_name} order by
|
23
|
+
#{find_table_name}.id DESC limit #{arg}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_by(arg1, arg2)
|
27
|
+
exe("select * from #{find_table_name} where
|
28
|
+
(#{find_table_name}.#{arg1} = '#{arg2}') limit 1")
|
29
|
+
end
|
30
|
+
|
31
|
+
def all
|
32
|
+
exe("select * from #{find_table_name}")
|
33
|
+
end
|
34
|
+
|
35
|
+
def making_query_from_hash(hash)
|
36
|
+
hash.inject('') { |s, (k, v)| s + "#{k} = '#{v}', " }
|
37
|
+
end
|
38
|
+
|
39
|
+
def update(hash, condn_hash)
|
40
|
+
str = making_query_from_hash(hash)
|
41
|
+
condn = making_query_from_hash(condn_hash)
|
42
|
+
exe("update #{to_s.downcase} set #{str[0..-3]} where #{condn[0..-3]}")
|
43
|
+
end
|
44
|
+
end
|
data/lib/rubylite.rb
CHANGED
@@ -1,5 +1,61 @@
|
|
1
|
-
|
1
|
+
require_relative 'functions.rb'
|
2
|
+
# this is class Rubylite
|
3
|
+
class Rubylite
|
4
|
+
def db_open(db_name)
|
5
|
+
@db = Amalgalite::Database.new "#{db_name}.db"
|
6
|
+
@current_db = db_name
|
7
|
+
make_class
|
8
|
+
end
|
2
9
|
|
3
|
-
|
4
|
-
|
10
|
+
def create(table_name, hash)
|
11
|
+
str = make_query(hash)
|
12
|
+
@db.execute("create table #{table_name.downcase}(#{str})")
|
13
|
+
str2 = make_query2(hash)
|
14
|
+
@db.execute("insert into #{table_name} values(#{str2})")
|
15
|
+
db_name = @current_db
|
16
|
+
db_close
|
17
|
+
db_open(db_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def make_query2(hash)
|
21
|
+
column = hash.inject('') { |col, (_k, value)| col + "'#{value}', " }
|
22
|
+
column[0..-3]
|
23
|
+
end
|
24
|
+
|
25
|
+
def make_query(hash)
|
26
|
+
column = hash.inject('') { |col, (key, _v)| col + "'#{key}', " }
|
27
|
+
column[0..-3]
|
28
|
+
end
|
29
|
+
|
30
|
+
def exec_this(db_name, query)
|
31
|
+
db_name.execute(query)
|
32
|
+
end
|
33
|
+
|
34
|
+
def db_close
|
35
|
+
@current_db = ''
|
36
|
+
end
|
37
|
+
|
38
|
+
def make_class
|
39
|
+
tables_list = exec_this(@db, "select name from sqlite_master where
|
40
|
+
type='table'")
|
41
|
+
tables_list.each do |table|
|
42
|
+
@class_created = Object.const_set((table[0])[0..-2].capitalize, Class.new)
|
43
|
+
@class_created.instance_variable_set(:@database, @db)
|
44
|
+
@class_created.class_eval do
|
45
|
+
extend Functions
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def eval_this(input)
|
51
|
+
instance_eval(input)
|
52
|
+
end
|
53
|
+
|
54
|
+
def code
|
55
|
+
print "#{@current_db}>>"
|
56
|
+
input = gets
|
57
|
+
exit if input =~ /^q$/
|
58
|
+
puts eval_this(input)
|
59
|
+
code
|
60
|
+
end
|
5
61
|
end
|
data/lib/rubylite/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.1.
|
1
|
+
module Version
|
2
|
+
VERSION = "0.1.1"
|
3
3
|
end
|
data/rubylite.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "rubylite/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rubylite"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Version::VERSION
|
9
9
|
spec.authors = ["vbhv007"]
|
10
10
|
spec.email = ["bhardwajvbhv@gmail.com"]
|
11
11
|
|
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.16"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
27
|
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
spec.add_development_dependency "amalgalite", "~> 1.6"
|
28
29
|
end
|
data/vbhv.db
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubylite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vbhv007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: amalgalite
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- bhardwajvbhv@gmail.com
|
@@ -70,16 +84,17 @@ files:
|
|
70
84
|
- bin/console
|
71
85
|
- bin/main.rb
|
72
86
|
- bin/setup
|
87
|
+
- bin/vbhv.db
|
73
88
|
- database/new.db
|
74
89
|
- database/qwerty.db
|
75
90
|
- database/test.db
|
76
91
|
- database/test2.db
|
77
92
|
- database/vbhv.db
|
78
|
-
- lib/
|
79
|
-
- lib/rquery.rb
|
93
|
+
- lib/functions.rb
|
80
94
|
- lib/rubylite.rb
|
81
95
|
- lib/rubylite/version.rb
|
82
96
|
- rubylite.gemspec
|
97
|
+
- vbhv.db
|
83
98
|
homepage: https://github.com/vbhv007/rubylite
|
84
99
|
licenses:
|
85
100
|
- MIT
|
data/lib/module.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'amalgalite'
|
2
|
-
# this is DB
|
3
|
-
module Functions
|
4
|
-
def exe(query)
|
5
|
-
RQuery.new.exec_this(@database, query)
|
6
|
-
end
|
7
|
-
|
8
|
-
def first(arg = 1)
|
9
|
-
exe("select * from #{to_s.downcase} order by
|
10
|
-
#{to_s.downcase}.id ASC limit #{arg}")
|
11
|
-
end
|
12
|
-
|
13
|
-
def take(arg = 1)
|
14
|
-
exe("select * from #{to_s.downcase} limit #{arg}")
|
15
|
-
end
|
16
|
-
|
17
|
-
def last(arg = 1)
|
18
|
-
exe("select * from #{to_s.downcase} order by
|
19
|
-
#{to_s.downcase}.id DESC limit #{arg}")
|
20
|
-
end
|
21
|
-
|
22
|
-
def find_by(arg1, arg2)
|
23
|
-
exe("select * from #{to_s.downcase} where
|
24
|
-
(#{to_s.downcase}.#{arg1} = '#{arg2}') limit 1")
|
25
|
-
end
|
26
|
-
|
27
|
-
def all
|
28
|
-
exe("select * from #{to_s.downcase}")
|
29
|
-
end
|
30
|
-
|
31
|
-
def update(hash, condn_hash)
|
32
|
-
str = hash.inject('') { |s, (k, v)| s + "#{k} = '#{v}', " }
|
33
|
-
condn = condn_hash.inject('') { |s, (k, v)| s + "#{k} = '#{v}', " }
|
34
|
-
exe("update #{to_s.downcase} set #{str[0..-3]} where #{condn[0..-3]}")
|
35
|
-
end
|
36
|
-
end
|
data/lib/rquery.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require_relative 'module.rb'
|
2
|
-
# this is class RQuery
|
3
|
-
class RQuery
|
4
|
-
def db_open(db_name)
|
5
|
-
@db = Amalgalite::Database.new "../database/#{db_name}.db"
|
6
|
-
@current_db = db_name
|
7
|
-
make_class
|
8
|
-
end
|
9
|
-
|
10
|
-
def create(table_name, hash)
|
11
|
-
str = make_query(hash)
|
12
|
-
@db.execute("create table #{table_name.downcase}(#{str})")
|
13
|
-
str2 = make_query2(hash)
|
14
|
-
@db.execute("insert into #{table_name} values(#{str2})")
|
15
|
-
db_name = @current_db
|
16
|
-
db_close
|
17
|
-
db_open(db_name)
|
18
|
-
end
|
19
|
-
|
20
|
-
def make_query2(hash)
|
21
|
-
column = hash.inject('') { |col, (_k, value)| col + "'#{value}', " }
|
22
|
-
column[0..-3]
|
23
|
-
end
|
24
|
-
|
25
|
-
def make_query(hash)
|
26
|
-
column = hash.inject('') { |col, (key, _v)| col + "'#{key}', " }
|
27
|
-
column[0..-3]
|
28
|
-
end
|
29
|
-
|
30
|
-
def exec_this(db_name, query)
|
31
|
-
db_name.execute(query)
|
32
|
-
end
|
33
|
-
|
34
|
-
def db_close
|
35
|
-
@current_db = ''
|
36
|
-
end
|
37
|
-
|
38
|
-
def make_class
|
39
|
-
tables_list = exec_this(@db, "select name from sqlite_master where
|
40
|
-
type='table'")
|
41
|
-
tables_list.each do |table|
|
42
|
-
@class_created = Object.const_set(table[0].capitalize, Class.new)
|
43
|
-
@class_created.instance_variable_set(:@database, @db)
|
44
|
-
@class_created.class_eval do
|
45
|
-
extend Functions
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def eval_this(input)
|
51
|
-
instance_eval(input)
|
52
|
-
end
|
53
|
-
|
54
|
-
def code
|
55
|
-
print "#{@current_db}>>"
|
56
|
-
input = gets
|
57
|
-
exit if input =~ /^q$/
|
58
|
-
puts eval_this(input)
|
59
|
-
code
|
60
|
-
end
|
61
|
-
end
|