whales_orm 0.1.0
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 +7 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +89 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +0 -0
- data/Rakefile +10 -0
- data/lib/associatable.rb +118 -0
- data/lib/base.rb +144 -0
- data/lib/db_connection.rb +46 -0
- data/lib/include_relation.rb +20 -0
- data/lib/query_methods.rb +14 -0
- data/lib/relation.rb +42 -0
- data/lib/whales_orm/version.rb +3 -0
- data/lib/whales_orm.rb +1 -0
- data/test_db/cats.db +0 -0
- data/test_db/cats.sql +70 -0
- data/whales_orm.gemspec +25 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6c084707f2e641cd075958da2ef02421455542ec
|
4
|
+
data.tar.gz: 7eabd7d7e6bbc2c94731088fd77220ab099123f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4bb583a9beb51730b671a3d84148602229debb0793542eec35758f8f6844a75d90f2568ac7f589b3ef19a72b9a457f226e69fae2d6902e8e930992915b25c579
|
7
|
+
data.tar.gz: cda5a993b27bb98a7114e9a00647588bbcaf15dd3e40deebbae6c6e0094e404d6df0acd56e5bd0874db129ee30ac270a70319c92134b197fb0346422a9231c83
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
whales_orm (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (4.2.4)
|
10
|
+
i18n (~> 0.7)
|
11
|
+
json (~> 1.7, >= 1.7.7)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
coderay (1.1.0)
|
16
|
+
diff-lcs (1.2.5)
|
17
|
+
ffi (1.9.10)
|
18
|
+
formatador (0.2.5)
|
19
|
+
guard (2.13.0)
|
20
|
+
formatador (>= 0.2.4)
|
21
|
+
listen (>= 2.7, <= 4.0)
|
22
|
+
lumberjack (~> 1.0)
|
23
|
+
nenv (~> 0.1)
|
24
|
+
notiffany (~> 0.0)
|
25
|
+
pry (>= 0.9.12)
|
26
|
+
shellany (~> 0.0)
|
27
|
+
thor (>= 0.18.1)
|
28
|
+
guard-compat (1.2.1)
|
29
|
+
guard-rspec (4.6.4)
|
30
|
+
guard (~> 2.1)
|
31
|
+
guard-compat (~> 1.1)
|
32
|
+
rspec (>= 2.99.0, < 4.0)
|
33
|
+
i18n (0.7.0)
|
34
|
+
json (1.8.3)
|
35
|
+
listen (3.0.5)
|
36
|
+
rb-fsevent (>= 0.9.3)
|
37
|
+
rb-inotify (>= 0.9)
|
38
|
+
lumberjack (1.0.9)
|
39
|
+
method_source (0.8.2)
|
40
|
+
minitest (5.8.3)
|
41
|
+
nenv (0.2.0)
|
42
|
+
notiffany (0.0.8)
|
43
|
+
nenv (~> 0.1)
|
44
|
+
shellany (~> 0.0)
|
45
|
+
pry (0.10.3)
|
46
|
+
coderay (~> 1.1.0)
|
47
|
+
method_source (~> 0.8.1)
|
48
|
+
slop (~> 3.4)
|
49
|
+
rake (10.4.2)
|
50
|
+
rb-fsevent (0.9.6)
|
51
|
+
rb-inotify (0.9.5)
|
52
|
+
ffi (>= 0.5.0)
|
53
|
+
rspec (3.4.0)
|
54
|
+
rspec-core (~> 3.4.0)
|
55
|
+
rspec-expectations (~> 3.4.0)
|
56
|
+
rspec-mocks (~> 3.4.0)
|
57
|
+
rspec-core (3.4.1)
|
58
|
+
rspec-support (~> 3.4.0)
|
59
|
+
rspec-expectations (3.4.0)
|
60
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
+
rspec-support (~> 3.4.0)
|
62
|
+
rspec-mocks (3.4.0)
|
63
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
+
rspec-support (~> 3.4.0)
|
65
|
+
rspec-support (3.4.1)
|
66
|
+
shellany (0.0.1)
|
67
|
+
slop (3.6.0)
|
68
|
+
sqlite3 (1.3.11)
|
69
|
+
thor (0.19.1)
|
70
|
+
thread_safe (0.3.5)
|
71
|
+
tzinfo (1.2.2)
|
72
|
+
thread_safe (~> 0.1)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
activesupport
|
79
|
+
bundler (~> 1.10)
|
80
|
+
guard
|
81
|
+
guard-rspec
|
82
|
+
pry
|
83
|
+
rake (~> 10.0)
|
84
|
+
rspec
|
85
|
+
sqlite3
|
86
|
+
whales_orm!
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
1.10.6
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 William Horton
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
# Default directory to look in is `/specs`
|
5
|
+
# Run with `rake spec`
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
data/lib/associatable.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
module WhalesORM
|
2
|
+
|
3
|
+
class AssocOptions
|
4
|
+
attr_accessor(
|
5
|
+
:foreign_key,
|
6
|
+
:class_name,
|
7
|
+
:primary_key
|
8
|
+
)
|
9
|
+
|
10
|
+
def model_class
|
11
|
+
class_name.constantize
|
12
|
+
end
|
13
|
+
|
14
|
+
def table_name
|
15
|
+
model_class.table_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class BelongsToOptions < WhalesORM::AssocOptions
|
20
|
+
def initialize(name, options = {})
|
21
|
+
options.each do |k, v|
|
22
|
+
send("#{k}=", v)
|
23
|
+
end
|
24
|
+
@primary_key ||= :id
|
25
|
+
@foreign_key ||= "#{name}_id".to_sym
|
26
|
+
@class_name ||= name.to_s.camelcase
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class HasManyOptions < WhalesORM::AssocOptions
|
32
|
+
def initialize(name, self_class_name, options = {})
|
33
|
+
options.each do |k, v|
|
34
|
+
send("#{k}=", v)
|
35
|
+
end
|
36
|
+
@primary_key ||= :id
|
37
|
+
@foreign_key ||= "#{self_class_name.underscore}_id".to_sym
|
38
|
+
@class_name ||= name.to_s.singularize.camelcase
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Associatable
|
43
|
+
def belongs_to(name, options = {})
|
44
|
+
opts = WhalesORM::BelongsToOptions.new(name.to_s, options)
|
45
|
+
|
46
|
+
define_method(name) do
|
47
|
+
foreign_key = send(opts.foreign_key)
|
48
|
+
opts.model_class.where(opts.primary_key => foreign_key).first
|
49
|
+
end
|
50
|
+
|
51
|
+
assoc_options[name] = opts
|
52
|
+
end
|
53
|
+
|
54
|
+
def has_many(name, options = {})
|
55
|
+
if options[:through]
|
56
|
+
has_one_or_many_through(name, options[:through], options[:source])
|
57
|
+
else
|
58
|
+
opts = WhalesORM::HasManyOptions.new(name.to_s, self.to_s, options)
|
59
|
+
|
60
|
+
define_method(name) do
|
61
|
+
primary_key_value = send(opts.primary_key)
|
62
|
+
where_clause = {opts.foreign_key => primary_key_value}
|
63
|
+
opts.model_class.where(where_clause)
|
64
|
+
end
|
65
|
+
|
66
|
+
assoc_options[name] = opts
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def assoc_options
|
71
|
+
@assoc_options ||= {}
|
72
|
+
end
|
73
|
+
|
74
|
+
def has_one_through(name, through_name, source_name)
|
75
|
+
# unless [through_options, source_options].all? { |opt| opt.is_a?(BelongsToOptions) }
|
76
|
+
# raise "has_one_through must use two belongs_to relations!"
|
77
|
+
# end
|
78
|
+
|
79
|
+
has_one_or_many_through(name, through_name, source_name, one: true)
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def has_one_or_many_through(name, through_name, source_name, type = {})
|
85
|
+
keywords = ["primary", "foreign"]
|
86
|
+
keywords.sort! if type[:one]
|
87
|
+
|
88
|
+
define_method(name) do
|
89
|
+
through_options = self.class.assoc_options[through_name]
|
90
|
+
source_options = through_options.model_class.assoc_options[source_name]
|
91
|
+
opts = [through_options, source_options]
|
92
|
+
|
93
|
+
key_value = send(through_options.send("#{keywords[0]}_key"))
|
94
|
+
key_name = through_options.send("#{keywords[1]}_key")
|
95
|
+
src_table = source_options.table_name
|
96
|
+
thr_table = through_options.table_name
|
97
|
+
|
98
|
+
results = DBConnection.execute(<<-SQL, key_value)
|
99
|
+
SELECT
|
100
|
+
#{src_table}.*
|
101
|
+
FROM
|
102
|
+
#{src_table}
|
103
|
+
JOIN
|
104
|
+
#{thr_table}
|
105
|
+
ON
|
106
|
+
#{thr_table}.#{source_options.foreign_key} = #{src_table}.#{source_options.primary_key}
|
107
|
+
WHERE
|
108
|
+
#{thr_table}.#{key_name} = ?
|
109
|
+
SQL
|
110
|
+
|
111
|
+
return nil if results.nil? || results.empty?
|
112
|
+
send_opts = (type[:one] ? [:new, results.first] : [:parse_all, results])
|
113
|
+
source_options.model_class.send(*send_opts)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
data/lib/base.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require_relative 'db_connection'
|
2
|
+
require_relative 'query_methods'
|
3
|
+
require_relative 'include_relation'
|
4
|
+
require_relative 'relation'
|
5
|
+
require_relative 'associatable'
|
6
|
+
|
7
|
+
require 'active_support/inflector'
|
8
|
+
|
9
|
+
module WhalesORM
|
10
|
+
class Base
|
11
|
+
extend WhalesORM::QueryMethods
|
12
|
+
extend WhalesORM::Associatable
|
13
|
+
|
14
|
+
def self.method_missing(method, *args)
|
15
|
+
method = method.to_s
|
16
|
+
if method.start_with?("find_by")
|
17
|
+
columns = method[8..-1].split("_and_")
|
18
|
+
opts = {}
|
19
|
+
columns.each_with_index do |col, i|
|
20
|
+
opts[col] = args[i]
|
21
|
+
end
|
22
|
+
self.where(opts)
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.columns
|
29
|
+
@columns ||= DBConnection.execute2("SELECT * FROM #{table_name} LIMIT 1")[0].map(&:to_sym)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.finalize!
|
33
|
+
columns.each do |col|
|
34
|
+
define_method(col) do
|
35
|
+
attributes[col]
|
36
|
+
end
|
37
|
+
|
38
|
+
define_method("#{col}=".to_sym) do |value|
|
39
|
+
attributes[col] = value
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.table_name=(table_name)
|
46
|
+
@table_name = table_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.table_name
|
50
|
+
@table_name ||= self.to_s.tableize
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.all
|
54
|
+
results = DBConnection.execute(<<-SQL)
|
55
|
+
SELECT
|
56
|
+
#{table_name}.*
|
57
|
+
FROM
|
58
|
+
#{table_name}
|
59
|
+
SQL
|
60
|
+
|
61
|
+
parse_all(results)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.parse_all(results)
|
65
|
+
results.map { |result| self.new(result) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.find(id)
|
69
|
+
result = DBConnection.instance.get_first_row(<<-SQL, id: id)
|
70
|
+
SELECT
|
71
|
+
#{table_name}.*
|
72
|
+
FROM
|
73
|
+
#{table_name}
|
74
|
+
WHERE
|
75
|
+
id = :id
|
76
|
+
SQL
|
77
|
+
|
78
|
+
result ? self.new(result) : nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def initialize(params = {})
|
82
|
+
params.each do |k, v|
|
83
|
+
attr_name = k.to_sym
|
84
|
+
|
85
|
+
send("#{attr_name}=", v)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def attributes
|
90
|
+
@attributes ||= {}
|
91
|
+
end
|
92
|
+
|
93
|
+
def attribute_values
|
94
|
+
self.class.columns.map { |attr_name| send(attr_name) }
|
95
|
+
end
|
96
|
+
|
97
|
+
def insert
|
98
|
+
col_names = self.class.columns.drop(1).join(',')
|
99
|
+
question_marks = (["?"] * (self.class.columns.length - 1)).join(',')
|
100
|
+
|
101
|
+
DBConnection.execute(<<-SQL, *(attribute_values.drop(1)))
|
102
|
+
INSERT INTO
|
103
|
+
#{self.class.table_name} (#{col_names})
|
104
|
+
VALUES
|
105
|
+
(#{question_marks});
|
106
|
+
SQL
|
107
|
+
|
108
|
+
self.id = DBConnection.last_insert_row_id
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def update
|
113
|
+
set_line = self.class.columns.map { |attr_name| "#{attr_name} = ?" }
|
114
|
+
set_line = set_line.join(', ')
|
115
|
+
|
116
|
+
DBConnection.execute(<<-SQL, *attribute_values, id)
|
117
|
+
UPDATE
|
118
|
+
#{self.class.table_name}
|
119
|
+
SET
|
120
|
+
#{set_line}
|
121
|
+
WHERE
|
122
|
+
id = ?
|
123
|
+
SQL
|
124
|
+
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
def save
|
129
|
+
id.nil? ? insert : update
|
130
|
+
end
|
131
|
+
|
132
|
+
def destroy
|
133
|
+
DBConnection.execute(<<-SQL, id)
|
134
|
+
DELETE FROM
|
135
|
+
#{self.class.table_name}
|
136
|
+
WHERE
|
137
|
+
id = ?
|
138
|
+
SQL
|
139
|
+
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
3
|
+
class DBConnection
|
4
|
+
def self.open(db_file_name)
|
5
|
+
@db = SQLite3::Database.new(db_file_name)
|
6
|
+
@db.results_as_hash = true
|
7
|
+
@db.type_translation = true
|
8
|
+
|
9
|
+
@db
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.reset
|
13
|
+
commands = [
|
14
|
+
"rm '#{DB_FILE}'",
|
15
|
+
"cat '#{SQL_FILE}' | sqlite3 '#{DB_FILE}'"
|
16
|
+
]
|
17
|
+
|
18
|
+
commands.each { |command| `#{command}` }
|
19
|
+
DBConnection.open(DB_FILE)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.instance
|
23
|
+
DBConnection.open(DB_FILE) if @db.nil?
|
24
|
+
|
25
|
+
@db
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.execute(*args)
|
29
|
+
|
30
|
+
instance.execute(*args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.execute2(*args)
|
34
|
+
|
35
|
+
instance.execute2(*args)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.last_insert_row_id
|
39
|
+
instance.last_insert_row_id
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def initialize(db_file_name)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module WhalesORM
|
2
|
+
class IncludeRelation < BasicObject
|
3
|
+
def initialize(class_name, sym_to_include, association)
|
4
|
+
@query = <<-SQL
|
5
|
+
SELECT
|
6
|
+
#{class_name.table_name}.*
|
7
|
+
FROM
|
8
|
+
#{class_name.table_name}
|
9
|
+
LEFT OUTER JOIN
|
10
|
+
#{association.table_name}
|
11
|
+
ON
|
12
|
+
#{class_name.table_name}.#{association.primary_key} = #{association.table_name}.#{association.foreign_key}
|
13
|
+
SQL
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module WhalesORM
|
2
|
+
module QueryMethods
|
3
|
+
def where(params)
|
4
|
+
WhalesORM::Relation.new(params, self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def includes(sym_to_include)
|
8
|
+
association = self.assoc_options[sym_to_include]
|
9
|
+
if association
|
10
|
+
WhalesORM::IncludeRelation.new(self, sym_to_include, association)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/relation.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative './db_connection.rb'
|
2
|
+
|
3
|
+
module WhalesORM
|
4
|
+
class Relation < BasicObject
|
5
|
+
|
6
|
+
def initialize(params, class_name)
|
7
|
+
@params = params
|
8
|
+
@class_name = class_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def where(params)
|
12
|
+
@params.merge(params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def where_line
|
16
|
+
@params.keys.map { |key| "#{key} = ?" }.join(" AND ")
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method, *args, &blk)
|
20
|
+
results = self.execute
|
21
|
+
results.send(method, *args, &blk)
|
22
|
+
end
|
23
|
+
|
24
|
+
def load
|
25
|
+
execute
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute
|
29
|
+
query = <<-SQL
|
30
|
+
SELECT
|
31
|
+
*
|
32
|
+
FROM
|
33
|
+
#{@class_name.table_name}
|
34
|
+
WHERE
|
35
|
+
#{where_line}
|
36
|
+
SQL
|
37
|
+
|
38
|
+
results = ::DBConnection.execute(query, *@params.values)
|
39
|
+
@class_name.parse_all(results)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/whales_orm.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'base'
|
data/test_db/cats.db
ADDED
Binary file
|
data/test_db/cats.sql
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
CREATE TABLE cats (
|
2
|
+
id INTEGER PRIMARY KEY,
|
3
|
+
name VARCHAR(255) NOT NULL,
|
4
|
+
owner_id INTEGER,
|
5
|
+
|
6
|
+
FOREIGN KEY(owner_id) REFERENCES human(id)
|
7
|
+
);
|
8
|
+
|
9
|
+
CREATE TABLE humans (
|
10
|
+
id INTEGER PRIMARY KEY,
|
11
|
+
fname VARCHAR(255) NOT NULL,
|
12
|
+
lname VARCHAR(255) NOT NULL,
|
13
|
+
house_id INTEGER,
|
14
|
+
|
15
|
+
FOREIGN KEY(house_id) REFERENCES human(id)
|
16
|
+
);
|
17
|
+
|
18
|
+
CREATE TABLE houses (
|
19
|
+
id INTEGER PRIMARY KEY,
|
20
|
+
address VARCHAR(255) NOT NULL
|
21
|
+
);
|
22
|
+
|
23
|
+
CREATE TABLE dogs (
|
24
|
+
id INTEGER PRIMARY KEY,
|
25
|
+
name VARCHAR(255) NOT NULL
|
26
|
+
);
|
27
|
+
|
28
|
+
CREATE TABLE walkings (
|
29
|
+
id INTEGER PRIMARY KEY,
|
30
|
+
dog_id INTEGER NOT NULL,
|
31
|
+
human_id INTEGER NOT NULL
|
32
|
+
);
|
33
|
+
|
34
|
+
INSERT INTO
|
35
|
+
houses (id, address)
|
36
|
+
VALUES
|
37
|
+
(1, "26th and Guerrero"), (2, "Dolores and Market");
|
38
|
+
|
39
|
+
INSERT INTO
|
40
|
+
humans (id, fname, lname, house_id)
|
41
|
+
VALUES
|
42
|
+
(1, "Devon", "Watts", 1),
|
43
|
+
(2, "Matt", "Rubens", 1),
|
44
|
+
(3, "Ned", "Ruggeri", 2),
|
45
|
+
(4, "Catless", "Human", NULL);
|
46
|
+
|
47
|
+
INSERT INTO
|
48
|
+
cats (id, name, owner_id)
|
49
|
+
VALUES
|
50
|
+
(1, "Breakfast", 1),
|
51
|
+
(2, "Earl", 2),
|
52
|
+
(3, "Haskell", 3),
|
53
|
+
(4, "Markov", 3),
|
54
|
+
(5, "Stray Cat", NULL);
|
55
|
+
|
56
|
+
INSERT INTO
|
57
|
+
dogs (id, name)
|
58
|
+
VALUES
|
59
|
+
(1, "Rover"),
|
60
|
+
(2, "Fido"),
|
61
|
+
(3, "Rex"),
|
62
|
+
(4, "Phoebe");
|
63
|
+
|
64
|
+
INSERT INTO
|
65
|
+
walkings (id, dog_id, human_id)
|
66
|
+
VALUES
|
67
|
+
(1, 1, 1),
|
68
|
+
(2, 2, 1),
|
69
|
+
(3, 3, 1),
|
70
|
+
(4, 1, 2);
|
data/whales_orm.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'whales_orm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "whales_orm"
|
8
|
+
spec.version = WhalesORM::VERSION
|
9
|
+
spec.authors = ["William Horton"]
|
10
|
+
spec.email = ["wdt.horton@gmail.com"]
|
11
|
+
spec.summary = %q{The ORM for the Whales Framework}
|
12
|
+
spec.homepage = "https://github.com/wdhorton/whales/tree/master/whales_actions"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
19
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
20
|
+
|
21
|
+
spec.add_development_dependency "rspec"
|
22
|
+
spec.add_development_dependency "guard"
|
23
|
+
spec.add_development_dependency "guard-rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whales_orm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Horton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- wdt.horton@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".rspec"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- Guardfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/associatable.rb
|
112
|
+
- lib/base.rb
|
113
|
+
- lib/db_connection.rb
|
114
|
+
- lib/include_relation.rb
|
115
|
+
- lib/query_methods.rb
|
116
|
+
- lib/relation.rb
|
117
|
+
- lib/whales_orm.rb
|
118
|
+
- lib/whales_orm/version.rb
|
119
|
+
- test_db/cats.db
|
120
|
+
- test_db/cats.sql
|
121
|
+
- whales_orm.gemspec
|
122
|
+
homepage: https://github.com/wdhorton/whales/tree/master/whales_actions
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.5.0
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: The ORM for the Whales Framework
|
146
|
+
test_files: []
|
147
|
+
has_rdoc:
|