automodel-sqlserver 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +81 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +225 -0
- data/Rakefile +6 -0
- data/automodel-sqlserver.gemspec +39 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Automodel.html +161 -0
- data/docs/Automodel/AdapterAlreadyRegistered.html +144 -0
- data/docs/Automodel/AdapterAlreadyRegisteredError.html +144 -0
- data/docs/Automodel/CannotFindOnCompoundPrimaryKey.html +144 -0
- data/docs/Automodel/Connectors.html +117 -0
- data/docs/Automodel/Error.html +140 -0
- data/docs/Automodel/FindOnCompoundPrimaryKeyError.html +144 -0
- data/docs/Automodel/Helpers.html +722 -0
- data/docs/Automodel/NameCollisionError.html +143 -0
- data/docs/Automodel/SchemaInspector.html +1046 -0
- data/docs/Automodel/UnregisteredAdapter.html +144 -0
- data/docs/_index.html +206 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.README.html +333 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +333 -0
- data/docs/js/app.js +292 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +155 -0
- data/docs/top-level-namespace.html +478 -0
- data/lib/automodel.rb +132 -0
- data/lib/automodel/automodel.rb +4 -0
- data/lib/automodel/connectors.rb +8 -0
- data/lib/automodel/errors.rb +24 -0
- data/lib/automodel/helpers.rb +141 -0
- data/lib/automodel/schema_inspector.rb +218 -0
- data/lib/automodel/version.rb +10 -0
- data/samples/database.yml +38 -0
- metadata +259 -0
@@ -0,0 +1,333 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.14
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="file_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'>
|
61
|
+
<h1 id="label-automodel-sqlserver+rdoc-image-3Ahttps-3A-2F-2Fbadge.fury.io-2Frb-2Fautomodel-sqlserver.svg">automodel-sqlserver <a href="https://badge.fury.io/rb/automodel-sqlserver"><img src="https://badge.fury.io/rb/automodel-sqlserver.svg"></a></h1>
|
62
|
+
|
63
|
+
<p>Connecting your Rails application to a database created outside of the
|
64
|
+
Rails environment usually means either spending hours writing up class
|
65
|
+
files for every table, or giving up on using the ActiveRecord query DSL and
|
66
|
+
resigning yourself to building SQL strings and making
|
67
|
+
<code>execute</code>/<code>exec_query</code> calls.</p>
|
68
|
+
|
69
|
+
<p>Are those SQL strings you're building even injection-safe? Hmm… 😟</p>
|
70
|
+
|
71
|
+
<p><em>With a single command</em>, <strong>automodel-sqlserver</strong> lets
|
72
|
+
you connect to any database and access all of its tables via the
|
73
|
+
ActiveRecord DSL you've grown to love!</p>
|
74
|
+
|
75
|
+
<p>It does this by analyzing the table structures and: - automatically
|
76
|
+
defining all of the corresponding model classes - declaring column aliases
|
77
|
+
so you can use Railsy names an idioms - constructing model relations based
|
78
|
+
on foreign key definitions</p>
|
79
|
+
|
80
|
+
<h2 id="label-Installation">Installation</h2>
|
81
|
+
|
82
|
+
<p>Add this line to your application's Gemfile:</p>
|
83
|
+
|
84
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>automodel-sqlserver</span><span class='tstring_end'>'</span></span>
|
85
|
+
</code></pre>
|
86
|
+
|
87
|
+
<p>And then execute:</p>
|
88
|
+
|
89
|
+
<pre class="code ruby"><code class="ruby">$ bundle</code></pre>
|
90
|
+
|
91
|
+
<p>Or install it yourself as:</p>
|
92
|
+
|
93
|
+
<pre class="code ruby"><code class="ruby">$ gem install automodel-sqlserver</code></pre>
|
94
|
+
|
95
|
+
<h4 id="label-Additional+Dependencies">Additional Dependencies</h4>
|
96
|
+
|
97
|
+
<p>If you are running on Windows and <strong>not</strong> using RubyInstaller,
|
98
|
+
the above steps are all that is needed.</p>
|
99
|
+
|
100
|
+
<p>On all other platforms, this gem (and its dependencies) alone are not
|
101
|
+
sufficient to connect to a SQL Server instance: <strong>you will also need
|
102
|
+
to <a href="https://github.com/rails-sqlserver/tiny_tds#install">install
|
103
|
+
FreeTDS on your system</a> if you haven't already</strong>.</p>
|
104
|
+
|
105
|
+
<h2 id="label-Using+Automodel">Using Automodel</h2>
|
106
|
+
|
107
|
+
<p>The following examples all assume a Postgres database with the following
|
108
|
+
tables: “`sql – Create Table: Authors CREATE TABLE public.“Authors” (
|
109
|
+
“Author ID” serial NOT NULL , “Name” varchar NOT NULL DEFAULT '',
|
110
|
+
“Birthday” date NULL , “Address” varchar NOT NULL DEFAULT '',</p>
|
111
|
+
|
112
|
+
<p>CONSTRAINT authors__pk PRIMARY KEY (“Author ID”) ) WITH ( OIDS=FALSE );</p>
|
113
|
+
|
114
|
+
<p>– Create Table: Publishers CREATE TABLE public.“Publishers” ( “Publisher
|
115
|
+
ID” serial NOT NULL , “Name” varchar NOT NULL DEFAULT '',
|
116
|
+
“Address” varchar NOT NULL DEFAULT '', “Website” varchar NOT NULL
|
117
|
+
DEFAULT '',</p>
|
118
|
+
|
119
|
+
<p>CONSTRAINT publishers__pk PRIMARY KEY (“Publisher ID”) ) WITH ( OIDS=FALSE
|
120
|
+
);</p>
|
121
|
+
|
122
|
+
<p>– Create Table: Books CREATE TABLE public.“Books” ( “Book ID” serial NOT
|
123
|
+
NULL , “Title” varchar NOT NULL DEFAULT '' , “Edition” int NOT
|
124
|
+
NULL DEFAULT 1 , “ISBN Number” varchar NOT NULL DEFAULT '' ,
|
125
|
+
“Published On” date NOT NULL , “Is Out Of Print” bool NOT NULL DEFAULT
|
126
|
+
FALSE, “Author ID” bigint NOT NULL , “Publisher ID” bigint NOT NULL ,</p>
|
127
|
+
|
128
|
+
<p>CONSTRAINT books__pk PRIMARY KEY (“Book ID”),</p>
|
129
|
+
|
130
|
+
<p>CONSTRAINT books_authors_fk FOREIGN KEY (“Author ID”) REFERENCES
|
131
|
+
public.“Authors”(“Author ID”),</p>
|
132
|
+
|
133
|
+
<p>CONSTRAINT books_publishers_fk FOREIGN KEY (“Publisher ID”) REFERENCES
|
134
|
+
public.“Publishers”(“Publisher ID”) ) WITH ( OIDS=FALSE ); “`</p>
|
135
|
+
<hr>
|
136
|
+
|
137
|
+
<h4 id="label-Connecting+To+The+External+Database">Connecting To The External Database</h4>
|
138
|
+
|
139
|
+
<p>You can provide the connection spec inline …</p>
|
140
|
+
|
141
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_automodel'><span class='object_link'><a href="top-level-namespace.html#automodel-instance_method" title="#automodel (method)">automodel</a></span></span> <span class='label'>adapter:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>postgresql</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
142
|
+
<span class='label'>encoding:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>unicode</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
143
|
+
<span class='label'>host:</span> <span class='id identifier rubyid_hostname'>hostname</span> <span class='comma'>,</span>
|
144
|
+
<span class='label'>port:</span> <span class='id identifier rubyid_port_number'>port_number</span> <span class='comma'>,</span>
|
145
|
+
<span class='label'>username:</span> <span class='id identifier rubyid_username'>username</span> <span class='comma'>,</span>
|
146
|
+
<span class='label'>password:</span> <span class='id identifier rubyid_password'>password</span> <span class='comma'>,</span>
|
147
|
+
<span class='label'>database:</span> <span class='id identifier rubyid_database_name'>database_name</span>
|
148
|
+
</code></pre>
|
149
|
+
|
150
|
+
<p>… or you can use a connection spec defined in “config/database.yml” …</p>
|
151
|
+
|
152
|
+
<pre class="code ruby"><code class="ruby">## In "database.yml" ...
|
153
|
+
|
154
|
+
## ... (your application's own db connection stuff) ...
|
155
|
+
|
156
|
+
|
157
|
+
external_db:
|
158
|
+
adapter: postgresql
|
159
|
+
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
|
160
|
+
timeouts: 5000
|
161
|
+
encoding: unicode
|
162
|
+
host: name_or_ip
|
163
|
+
port: port_number
|
164
|
+
username: username
|
165
|
+
password: password
|
166
|
+
database: sample_db</code></pre>
|
167
|
+
|
168
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'>## In "config/puma.rb" or "config/unicorn.rb" ...
|
169
|
+
</span>
|
170
|
+
<span class='id identifier rubyid_automodel'><span class='object_link'><a href="top-level-namespace.html#automodel-instance_method" title="#automodel (method)">automodel</a></span></span> <span class='symbol'>:external_db</span>
|
171
|
+
</code></pre>
|
172
|
+
<hr>
|
173
|
+
|
174
|
+
<h4 id="label-Using+The+Automodel-27ed+Objects">Using The Automodel'ed Objects</h4>
|
175
|
+
|
176
|
+
<p>Connecting via either method above will allow you to issue all of the
|
177
|
+
following expressions, just as if these were your own models:</p>
|
178
|
+
|
179
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'>## ISBNs for all non-first-edition books.
|
180
|
+
</span><span class='id identifier rubyid_isbn_list'>isbn_list</span> <span class='op'>=</span> <span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='period'>.</span><span class='id identifier rubyid_not'>not</span><span class='lparen'>(</span><span class='label'>edition:</span> <span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_pluck'>pluck</span><span class='lparen'>(</span><span class='symbol'>:isbn_number</span><span class='rparen'>)</span>
|
181
|
+
|
182
|
+
<span class='comment'>## Take any book and look up some values.
|
183
|
+
</span><span class='id identifier rubyid_book'>book</span> <span class='op'>=</span> <span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span>
|
184
|
+
<span class='id identifier rubyid_book'>book</span><span class='period'>.</span><span class='id identifier rubyid_title'>title</span>
|
185
|
+
<span class='id identifier rubyid_book'>book</span><span class='period'>.</span><span class='id identifier rubyid_out_of_print?'>out_of_print?</span>
|
186
|
+
<span class='id identifier rubyid_book'>book</span><span class='period'>.</span><span class='id identifier rubyid_publisher'>publisher</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span>
|
187
|
+
|
188
|
+
|
189
|
+
<span class='comment'>## Note that some ActiveRecord constructs surface real table names,
|
190
|
+
</span><span class='comment'>## which can look awkward in code when working with tables with non-Railsy names:
|
191
|
+
</span><span class='comment'>## (the uppercase "P" in "Publishers" below makes it look like a class reference)
|
192
|
+
</span><span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_joins'>joins</span><span class='lparen'>(</span><span class='symbol'>:Publishers</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>Publishers:</span> <span class='lbrace'>{</span> <span class='label'>name:</span> <span class='id identifier rubyid_test_value'>test_value</span> <span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span>
|
193
|
+
</code></pre>
|
194
|
+
<hr>
|
195
|
+
|
196
|
+
<h4 id="label-Automodel+With+Namespacing">Automodel With Namespacing</h4>
|
197
|
+
|
198
|
+
<p>If you're worried about model name collisions (or just want to keep the
|
199
|
+
global namespace tidy), Automodel can define all of the new model classes
|
200
|
+
under a module.</p>
|
201
|
+
|
202
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_automodel'><span class='object_link'><a href="top-level-namespace.html#automodel-instance_method" title="#automodel (method)">automodel</a></span></span> <span class='label'>adapter:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>postgresql</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
203
|
+
<span class='label'>encoding:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>unicode</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
204
|
+
<span class='label'>host:</span> <span class='id identifier rubyid_hostname'>hostname</span> <span class='comma'>,</span>
|
205
|
+
<span class='label'>port:</span> <span class='id identifier rubyid_port_number'>port_number</span> <span class='comma'>,</span>
|
206
|
+
<span class='label'>username:</span> <span class='id identifier rubyid_username'>username</span> <span class='comma'>,</span>
|
207
|
+
<span class='label'>password:</span> <span class='id identifier rubyid_password'>password</span> <span class='comma'>,</span>
|
208
|
+
<span class='label'>database:</span> <span class='id identifier rubyid_database_name'>database_name</span><span class='comma'>,</span>
|
209
|
+
<span class='label'>namespace:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ExternalDB</span><span class='tstring_end'>'</span></span>
|
210
|
+
|
211
|
+
<span class='comment'>## Now you can do everything you'd expect, but the models are namespaced under ExternalDB.
|
212
|
+
</span><span class='const'>ExternalDB</span><span class='op'>::</span><span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span> <span class='comment'>## => Book #5
|
213
|
+
</span><span class='const'>ExternalDB</span><span class='op'>::</span><span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='period'>.</span><span class='id identifier rubyid_author'>author</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='comment'>## => ExternalDB::Author
|
214
|
+
</span></code></pre>
|
215
|
+
<hr>
|
216
|
+
|
217
|
+
<p><a
|
218
|
+
href="http://nestor-custodio.github.io/automodel-sqlserver/top-level-namespace.html#automodel-instance_method">Consult
|
219
|
+
the repo docs for the full automodel-sqlserver documentation.</a></p>
|
220
|
+
|
221
|
+
<h2 id="label-FAQs">FAQs</h2>
|
222
|
+
<ul><li>
|
223
|
+
<h5 id="label-Do+I+have+to+add+anything+to+my+Gemfile+besides+-27automodel-sqlserver-27-3F">Do I have to add anything to my Gemfile besides <code>'automodel-sqlserver'</code>?</h5>
|
224
|
+
|
225
|
+
<p>Due to the nature of this version of the gem, it is assumed you will want
|
226
|
+
to connect to a SQL Server database, so both <strong><a
|
227
|
+
href="https://github.com/rails-sqlserver/activerecord-sqlserver-adapter">activerecord-sqlserver-adapter</a></strong>
|
228
|
+
and the <strong><a
|
229
|
+
href="https://github.com/rails-sqlserver/tiny_tds">tiny_tds</a></strong>
|
230
|
+
gems are included as dependencies (meaning you don't have to worry
|
231
|
+
about them). Note that these gems alone are not sufficient to connect to a
|
232
|
+
SQL Server instance, however: <strong>you still need to <a
|
233
|
+
href="https://github.com/rails-sqlserver/tiny_tds#install">install FreeTDS
|
234
|
+
on your system</a> if you haven't already</strong>.</p>
|
235
|
+
</li></ul>
|
236
|
+
|
237
|
+
<p>SQL Server aside, you will need to add the corresponding gems if you want
|
238
|
+
to use connection adapters that are not yet part of your gemset. (e.g.
|
239
|
+
Don't expect to be able to connect to a MySQL database without having
|
240
|
+
added <code>'mysql2'</code> to your Gemfile.)</p>
|
241
|
+
<ul><li>
|
242
|
+
<h5 id="label-But+what+about+my+application-27s+own+models-3F">But what about my application's own models?</h5>
|
243
|
+
|
244
|
+
<p>You can call <code>automodel</code> <strong>and</strong> continue to use
|
245
|
+
your application's own models without changing a single line of code.</p>
|
246
|
+
</li><li>
|
247
|
+
<h5 id="label-Can+I+Automodel+more+than+one+database-3F">Can I Automodel more than one database?</h5>
|
248
|
+
|
249
|
+
<p>Yes! You can Automodel as many databases with as many different adapters
|
250
|
+
as you like. <strong>automodel-sqlserver</strong> takes care of connecting
|
251
|
+
to the various databases and managing their connection pools for you.</p>
|
252
|
+
</li><li>
|
253
|
+
<h5 id="label-What+about+model+name+collisions-3F">What about model name collisions?</h5>
|
254
|
+
|
255
|
+
<p>If an <code>automodel</code> call will result in a class name collision,
|
256
|
+
an Automodel::NameCollisionError is raised <em>before</em> any classes are
|
257
|
+
clobbered.</p>
|
258
|
+
</li><li>
|
259
|
+
<h5 id="label-What+if+I+want+custom+methods+for+certain+models-3F">What if I want custom methods for certain models?</h5>
|
260
|
+
|
261
|
+
<p>You can either monkey-patch your methods onto the applicable
|
262
|
+
Automodel-generated classes once they've been defined, or you can
|
263
|
+
monkey-patch the method onto the connection handler class returned by the
|
264
|
+
<code>automodel</code> call itself, which will make it available for all
|
265
|
+
models generated <em>by that call</em>.</p>
|
266
|
+
</li><li>
|
267
|
+
<h5 id="label-What+if+I-27m+using+ActiveRecord+but+not+Rails-3F">What if I'm using ActiveRecord but not Rails?</h5>
|
268
|
+
|
269
|
+
<p>That's no problem at all! The <strong>automodel-sqlserver</strong> gem
|
270
|
+
depends on ActiveRecord – not Rails. Adding
|
271
|
+
<code>'automodel-sqlserver'</code> to your Gemfile (along with any
|
272
|
+
relevant connection adapters, of course) is all you need to make use of the
|
273
|
+
tool in your vanilla-Ruby project. Just be mindful that – since
|
274
|
+
“config/database.yml” isn't available (as you're not using Rails) –
|
275
|
+
you'll always need to pass in a full connection spec to your
|
276
|
+
<code>automodel</code> calls (as in the very first example, under
|
277
|
+
<em>“Connecting To The External Database”</em> above).</p>
|
278
|
+
</li></ul>
|
279
|
+
|
280
|
+
<h2 id="label-Feature+Roadmap+-2F+Future+Development">Feature Roadmap / Future Development</h2>
|
281
|
+
|
282
|
+
<p>Additional features/options coming in the future:</p>
|
283
|
+
<ul><li>
|
284
|
+
<p><strong>Naming</strong>: Better generation of Railsy names for
|
285
|
+
<code>:date</code>/<code>:datetime</code> column types.</p>
|
286
|
+
</li><li>
|
287
|
+
<p><strong>Reads</strong>: Support for <code>#find</code> on tables with
|
288
|
+
composite primary keys.</p>
|
289
|
+
</li><li>
|
290
|
+
<p><strong>Writes</strong>: Better handling of missing
|
291
|
+
<code>created_at</code>/<code>updated_at</code> columns on record
|
292
|
+
creation/updates.</p>
|
293
|
+
</li><li>
|
294
|
+
<p><strong>Traversal</strong>: Support for <code>has_many</code> relations
|
295
|
+
(only <code>belongs_to</code> is currently supported).</p>
|
296
|
+
</li><li>
|
297
|
+
<p><strong>Traversal</strong>: Support for self-referential foreign keys.</p>
|
298
|
+
</li><li>
|
299
|
+
<p><strong>Traversal</strong>: Support for multiple relations to the same
|
300
|
+
target model.</p>
|
301
|
+
</li></ul>
|
302
|
+
|
303
|
+
<h2 id="label-Contribution+-2F+Development">Contribution / Development</h2>
|
304
|
+
|
305
|
+
<p>Bug reports and pull requests are welcome on GitHub at <a
|
306
|
+
href="https://github.com/nestor-custodio/automodel-sqlserver">github.com/nestor-custodio/automodel-sqlserver</a>.</p>
|
307
|
+
|
308
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install
|
309
|
+
dependencies. Then, run <code>rake spec</code> to run the tests. You can
|
310
|
+
also run <code>bin/console</code> for an interactive prompt that will allow
|
311
|
+
you to experiment.</p>
|
312
|
+
|
313
|
+
<p>Linting is courtesy of <a
|
314
|
+
href="https://github.com/bbatsov/rubocop">Rubocop</a> and documentation is
|
315
|
+
built using <a href="https://yardoc.org/">Yard</a>. Neither is included in
|
316
|
+
the Gemspec; you'll need to install these locally (<code>gem install
|
317
|
+
rubocop yard</code>) to take advantage.</p>
|
318
|
+
|
319
|
+
<h2 id="label-License">License</h2>
|
320
|
+
|
321
|
+
<p>The gem is available as open source under the terms of the <a
|
322
|
+
href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
323
|
+
</div></div>
|
324
|
+
|
325
|
+
<div id="footer">
|
326
|
+
Generated on Wed Jun 20 18:16:10 2018 by
|
327
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
328
|
+
0.9.14 (ruby-2.4.4).
|
329
|
+
</div>
|
330
|
+
|
331
|
+
</div>
|
332
|
+
</body>
|
333
|
+
</html>
|
data/docs/file_list.html
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">File List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="file">
|
45
|
+
|
46
|
+
|
47
|
+
<li id="object_README" class="odd">
|
48
|
+
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
49
|
+
</li>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
data/docs/frames.html
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>Documentation by YARD 0.9.14</title>
|
6
|
+
</head>
|
7
|
+
<script type="text/javascript" charset="utf-8">
|
8
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
9
|
+
var name = match ? match[1] : 'index.html';
|
10
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
11
|
+
window.top.location = name;
|
12
|
+
</script>
|
13
|
+
<noscript>
|
14
|
+
<h1>Oops!</h1>
|
15
|
+
<h2>YARD requires JavaScript!</h2>
|
16
|
+
</noscript>
|
17
|
+
</html>
|
data/docs/index.html
ADDED
@@ -0,0 +1,333 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.14
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "README";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
<span class="title">File: README</span>
|
41
|
+
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<div id="search">
|
45
|
+
|
46
|
+
<a class="full_list_link" id="class_list_link"
|
47
|
+
href="class_list.html">
|
48
|
+
|
49
|
+
<svg width="24" height="24">
|
50
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
51
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
52
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
</svg>
|
54
|
+
</a>
|
55
|
+
|
56
|
+
</div>
|
57
|
+
<div class="clear"></div>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="content"><div id='filecontents'>
|
61
|
+
<h1 id="label-automodel-sqlserver+rdoc-image-3Ahttps-3A-2F-2Fbadge.fury.io-2Frb-2Fautomodel-sqlserver.svg">automodel-sqlserver <a href="https://badge.fury.io/rb/automodel-sqlserver"><img src="https://badge.fury.io/rb/automodel-sqlserver.svg"></a></h1>
|
62
|
+
|
63
|
+
<p>Connecting your Rails application to a database created outside of the
|
64
|
+
Rails environment usually means either spending hours writing up class
|
65
|
+
files for every table, or giving up on using the ActiveRecord query DSL and
|
66
|
+
resigning yourself to building SQL strings and making
|
67
|
+
<code>execute</code>/<code>exec_query</code> calls.</p>
|
68
|
+
|
69
|
+
<p>Are those SQL strings you're building even injection-safe? Hmm… 😟</p>
|
70
|
+
|
71
|
+
<p><em>With a single command</em>, <strong>automodel-sqlserver</strong> lets
|
72
|
+
you connect to any database and access all of its tables via the
|
73
|
+
ActiveRecord DSL you've grown to love!</p>
|
74
|
+
|
75
|
+
<p>It does this by analyzing the table structures and: - automatically
|
76
|
+
defining all of the corresponding model classes - declaring column aliases
|
77
|
+
so you can use Railsy names an idioms - constructing model relations based
|
78
|
+
on foreign key definitions</p>
|
79
|
+
|
80
|
+
<h2 id="label-Installation">Installation</h2>
|
81
|
+
|
82
|
+
<p>Add this line to your application's Gemfile:</p>
|
83
|
+
|
84
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>automodel-sqlserver</span><span class='tstring_end'>'</span></span>
|
85
|
+
</code></pre>
|
86
|
+
|
87
|
+
<p>And then execute:</p>
|
88
|
+
|
89
|
+
<pre class="code ruby"><code class="ruby">$ bundle</code></pre>
|
90
|
+
|
91
|
+
<p>Or install it yourself as:</p>
|
92
|
+
|
93
|
+
<pre class="code ruby"><code class="ruby">$ gem install automodel-sqlserver</code></pre>
|
94
|
+
|
95
|
+
<h4 id="label-Additional+Dependencies">Additional Dependencies</h4>
|
96
|
+
|
97
|
+
<p>If you are running on Windows and <strong>not</strong> using RubyInstaller,
|
98
|
+
the above steps are all that is needed.</p>
|
99
|
+
|
100
|
+
<p>On all other platforms, this gem (and its dependencies) alone are not
|
101
|
+
sufficient to connect to a SQL Server instance: <strong>you will also need
|
102
|
+
to <a href="https://github.com/rails-sqlserver/tiny_tds#install">install
|
103
|
+
FreeTDS on your system</a> if you haven't already</strong>.</p>
|
104
|
+
|
105
|
+
<h2 id="label-Using+Automodel">Using Automodel</h2>
|
106
|
+
|
107
|
+
<p>The following examples all assume a Postgres database with the following
|
108
|
+
tables: “`sql – Create Table: Authors CREATE TABLE public.“Authors” (
|
109
|
+
“Author ID” serial NOT NULL , “Name” varchar NOT NULL DEFAULT '',
|
110
|
+
“Birthday” date NULL , “Address” varchar NOT NULL DEFAULT '',</p>
|
111
|
+
|
112
|
+
<p>CONSTRAINT authors__pk PRIMARY KEY (“Author ID”) ) WITH ( OIDS=FALSE );</p>
|
113
|
+
|
114
|
+
<p>– Create Table: Publishers CREATE TABLE public.“Publishers” ( “Publisher
|
115
|
+
ID” serial NOT NULL , “Name” varchar NOT NULL DEFAULT '',
|
116
|
+
“Address” varchar NOT NULL DEFAULT '', “Website” varchar NOT NULL
|
117
|
+
DEFAULT '',</p>
|
118
|
+
|
119
|
+
<p>CONSTRAINT publishers__pk PRIMARY KEY (“Publisher ID”) ) WITH ( OIDS=FALSE
|
120
|
+
);</p>
|
121
|
+
|
122
|
+
<p>– Create Table: Books CREATE TABLE public.“Books” ( “Book ID” serial NOT
|
123
|
+
NULL , “Title” varchar NOT NULL DEFAULT '' , “Edition” int NOT
|
124
|
+
NULL DEFAULT 1 , “ISBN Number” varchar NOT NULL DEFAULT '' ,
|
125
|
+
“Published On” date NOT NULL , “Is Out Of Print” bool NOT NULL DEFAULT
|
126
|
+
FALSE, “Author ID” bigint NOT NULL , “Publisher ID” bigint NOT NULL ,</p>
|
127
|
+
|
128
|
+
<p>CONSTRAINT books__pk PRIMARY KEY (“Book ID”),</p>
|
129
|
+
|
130
|
+
<p>CONSTRAINT books_authors_fk FOREIGN KEY (“Author ID”) REFERENCES
|
131
|
+
public.“Authors”(“Author ID”),</p>
|
132
|
+
|
133
|
+
<p>CONSTRAINT books_publishers_fk FOREIGN KEY (“Publisher ID”) REFERENCES
|
134
|
+
public.“Publishers”(“Publisher ID”) ) WITH ( OIDS=FALSE ); “`</p>
|
135
|
+
<hr>
|
136
|
+
|
137
|
+
<h4 id="label-Connecting+To+The+External+Database">Connecting To The External Database</h4>
|
138
|
+
|
139
|
+
<p>You can provide the connection spec inline …</p>
|
140
|
+
|
141
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_automodel'><span class='object_link'><a href="top-level-namespace.html#automodel-instance_method" title="#automodel (method)">automodel</a></span></span> <span class='label'>adapter:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>postgresql</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
142
|
+
<span class='label'>encoding:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>unicode</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
143
|
+
<span class='label'>host:</span> <span class='id identifier rubyid_hostname'>hostname</span> <span class='comma'>,</span>
|
144
|
+
<span class='label'>port:</span> <span class='id identifier rubyid_port_number'>port_number</span> <span class='comma'>,</span>
|
145
|
+
<span class='label'>username:</span> <span class='id identifier rubyid_username'>username</span> <span class='comma'>,</span>
|
146
|
+
<span class='label'>password:</span> <span class='id identifier rubyid_password'>password</span> <span class='comma'>,</span>
|
147
|
+
<span class='label'>database:</span> <span class='id identifier rubyid_database_name'>database_name</span>
|
148
|
+
</code></pre>
|
149
|
+
|
150
|
+
<p>… or you can use a connection spec defined in “config/database.yml” …</p>
|
151
|
+
|
152
|
+
<pre class="code ruby"><code class="ruby">## In "database.yml" ...
|
153
|
+
|
154
|
+
## ... (your application's own db connection stuff) ...
|
155
|
+
|
156
|
+
|
157
|
+
external_db:
|
158
|
+
adapter: postgresql
|
159
|
+
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
|
160
|
+
timeouts: 5000
|
161
|
+
encoding: unicode
|
162
|
+
host: name_or_ip
|
163
|
+
port: port_number
|
164
|
+
username: username
|
165
|
+
password: password
|
166
|
+
database: sample_db</code></pre>
|
167
|
+
|
168
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'>## In "config/puma.rb" or "config/unicorn.rb" ...
|
169
|
+
</span>
|
170
|
+
<span class='id identifier rubyid_automodel'><span class='object_link'><a href="top-level-namespace.html#automodel-instance_method" title="#automodel (method)">automodel</a></span></span> <span class='symbol'>:external_db</span>
|
171
|
+
</code></pre>
|
172
|
+
<hr>
|
173
|
+
|
174
|
+
<h4 id="label-Using+The+Automodel-27ed+Objects">Using The Automodel'ed Objects</h4>
|
175
|
+
|
176
|
+
<p>Connecting via either method above will allow you to issue all of the
|
177
|
+
following expressions, just as if these were your own models:</p>
|
178
|
+
|
179
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'>## ISBNs for all non-first-edition books.
|
180
|
+
</span><span class='id identifier rubyid_isbn_list'>isbn_list</span> <span class='op'>=</span> <span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='period'>.</span><span class='id identifier rubyid_not'>not</span><span class='lparen'>(</span><span class='label'>edition:</span> <span class='int'>1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_pluck'>pluck</span><span class='lparen'>(</span><span class='symbol'>:isbn_number</span><span class='rparen'>)</span>
|
181
|
+
|
182
|
+
<span class='comment'>## Take any book and look up some values.
|
183
|
+
</span><span class='id identifier rubyid_book'>book</span> <span class='op'>=</span> <span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span>
|
184
|
+
<span class='id identifier rubyid_book'>book</span><span class='period'>.</span><span class='id identifier rubyid_title'>title</span>
|
185
|
+
<span class='id identifier rubyid_book'>book</span><span class='period'>.</span><span class='id identifier rubyid_out_of_print?'>out_of_print?</span>
|
186
|
+
<span class='id identifier rubyid_book'>book</span><span class='period'>.</span><span class='id identifier rubyid_publisher'>publisher</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span>
|
187
|
+
|
188
|
+
|
189
|
+
<span class='comment'>## Note that some ActiveRecord constructs surface real table names,
|
190
|
+
</span><span class='comment'>## which can look awkward in code when working with tables with non-Railsy names:
|
191
|
+
</span><span class='comment'>## (the uppercase "P" in "Publishers" below makes it look like a class reference)
|
192
|
+
</span><span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_joins'>joins</span><span class='lparen'>(</span><span class='symbol'>:Publishers</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_where'>where</span><span class='lparen'>(</span><span class='label'>Publishers:</span> <span class='lbrace'>{</span> <span class='label'>name:</span> <span class='id identifier rubyid_test_value'>test_value</span> <span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_all'>all</span>
|
193
|
+
</code></pre>
|
194
|
+
<hr>
|
195
|
+
|
196
|
+
<h4 id="label-Automodel+With+Namespacing">Automodel With Namespacing</h4>
|
197
|
+
|
198
|
+
<p>If you're worried about model name collisions (or just want to keep the
|
199
|
+
global namespace tidy), Automodel can define all of the new model classes
|
200
|
+
under a module.</p>
|
201
|
+
|
202
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_automodel'><span class='object_link'><a href="top-level-namespace.html#automodel-instance_method" title="#automodel (method)">automodel</a></span></span> <span class='label'>adapter:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>postgresql</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
203
|
+
<span class='label'>encoding:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>unicode</span><span class='tstring_end'>'</span></span> <span class='comma'>,</span>
|
204
|
+
<span class='label'>host:</span> <span class='id identifier rubyid_hostname'>hostname</span> <span class='comma'>,</span>
|
205
|
+
<span class='label'>port:</span> <span class='id identifier rubyid_port_number'>port_number</span> <span class='comma'>,</span>
|
206
|
+
<span class='label'>username:</span> <span class='id identifier rubyid_username'>username</span> <span class='comma'>,</span>
|
207
|
+
<span class='label'>password:</span> <span class='id identifier rubyid_password'>password</span> <span class='comma'>,</span>
|
208
|
+
<span class='label'>database:</span> <span class='id identifier rubyid_database_name'>database_name</span><span class='comma'>,</span>
|
209
|
+
<span class='label'>namespace:</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ExternalDB</span><span class='tstring_end'>'</span></span>
|
210
|
+
|
211
|
+
<span class='comment'>## Now you can do everything you'd expect, but the models are namespaced under ExternalDB.
|
212
|
+
</span><span class='const'>ExternalDB</span><span class='op'>::</span><span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_find'>find</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span> <span class='comment'>## => Book #5
|
213
|
+
</span><span class='const'>ExternalDB</span><span class='op'>::</span><span class='const'>Book</span><span class='period'>.</span><span class='id identifier rubyid_take'>take</span><span class='period'>.</span><span class='id identifier rubyid_author'>author</span><span class='period'>.</span><span class='id identifier rubyid_class'>class</span> <span class='comment'>## => ExternalDB::Author
|
214
|
+
</span></code></pre>
|
215
|
+
<hr>
|
216
|
+
|
217
|
+
<p><a
|
218
|
+
href="http://nestor-custodio.github.io/automodel-sqlserver/top-level-namespace.html#automodel-instance_method">Consult
|
219
|
+
the repo docs for the full automodel-sqlserver documentation.</a></p>
|
220
|
+
|
221
|
+
<h2 id="label-FAQs">FAQs</h2>
|
222
|
+
<ul><li>
|
223
|
+
<h5 id="label-Do+I+have+to+add+anything+to+my+Gemfile+besides+-27automodel-sqlserver-27-3F">Do I have to add anything to my Gemfile besides <code>'automodel-sqlserver'</code>?</h5>
|
224
|
+
|
225
|
+
<p>Due to the nature of this version of the gem, it is assumed you will want
|
226
|
+
to connect to a SQL Server database, so both <strong><a
|
227
|
+
href="https://github.com/rails-sqlserver/activerecord-sqlserver-adapter">activerecord-sqlserver-adapter</a></strong>
|
228
|
+
and the <strong><a
|
229
|
+
href="https://github.com/rails-sqlserver/tiny_tds">tiny_tds</a></strong>
|
230
|
+
gems are included as dependencies (meaning you don't have to worry
|
231
|
+
about them). Note that these gems alone are not sufficient to connect to a
|
232
|
+
SQL Server instance, however: <strong>you still need to <a
|
233
|
+
href="https://github.com/rails-sqlserver/tiny_tds#install">install FreeTDS
|
234
|
+
on your system</a> if you haven't already</strong>.</p>
|
235
|
+
</li></ul>
|
236
|
+
|
237
|
+
<p>SQL Server aside, you will need to add the corresponding gems if you want
|
238
|
+
to use connection adapters that are not yet part of your gemset. (e.g.
|
239
|
+
Don't expect to be able to connect to a MySQL database without having
|
240
|
+
added <code>'mysql2'</code> to your Gemfile.)</p>
|
241
|
+
<ul><li>
|
242
|
+
<h5 id="label-But+what+about+my+application-27s+own+models-3F">But what about my application's own models?</h5>
|
243
|
+
|
244
|
+
<p>You can call <code>automodel</code> <strong>and</strong> continue to use
|
245
|
+
your application's own models without changing a single line of code.</p>
|
246
|
+
</li><li>
|
247
|
+
<h5 id="label-Can+I+Automodel+more+than+one+database-3F">Can I Automodel more than one database?</h5>
|
248
|
+
|
249
|
+
<p>Yes! You can Automodel as many databases with as many different adapters
|
250
|
+
as you like. <strong>automodel-sqlserver</strong> takes care of connecting
|
251
|
+
to the various databases and managing their connection pools for you.</p>
|
252
|
+
</li><li>
|
253
|
+
<h5 id="label-What+about+model+name+collisions-3F">What about model name collisions?</h5>
|
254
|
+
|
255
|
+
<p>If an <code>automodel</code> call will result in a class name collision,
|
256
|
+
an Automodel::NameCollisionError is raised <em>before</em> any classes are
|
257
|
+
clobbered.</p>
|
258
|
+
</li><li>
|
259
|
+
<h5 id="label-What+if+I+want+custom+methods+for+certain+models-3F">What if I want custom methods for certain models?</h5>
|
260
|
+
|
261
|
+
<p>You can either monkey-patch your methods onto the applicable
|
262
|
+
Automodel-generated classes once they've been defined, or you can
|
263
|
+
monkey-patch the method onto the connection handler class returned by the
|
264
|
+
<code>automodel</code> call itself, which will make it available for all
|
265
|
+
models generated <em>by that call</em>.</p>
|
266
|
+
</li><li>
|
267
|
+
<h5 id="label-What+if+I-27m+using+ActiveRecord+but+not+Rails-3F">What if I'm using ActiveRecord but not Rails?</h5>
|
268
|
+
|
269
|
+
<p>That's no problem at all! The <strong>automodel-sqlserver</strong> gem
|
270
|
+
depends on ActiveRecord – not Rails. Adding
|
271
|
+
<code>'automodel-sqlserver'</code> to your Gemfile (along with any
|
272
|
+
relevant connection adapters, of course) is all you need to make use of the
|
273
|
+
tool in your vanilla-Ruby project. Just be mindful that – since
|
274
|
+
“config/database.yml” isn't available (as you're not using Rails) –
|
275
|
+
you'll always need to pass in a full connection spec to your
|
276
|
+
<code>automodel</code> calls (as in the very first example, under
|
277
|
+
<em>“Connecting To The External Database”</em> above).</p>
|
278
|
+
</li></ul>
|
279
|
+
|
280
|
+
<h2 id="label-Feature+Roadmap+-2F+Future+Development">Feature Roadmap / Future Development</h2>
|
281
|
+
|
282
|
+
<p>Additional features/options coming in the future:</p>
|
283
|
+
<ul><li>
|
284
|
+
<p><strong>Naming</strong>: Better generation of Railsy names for
|
285
|
+
<code>:date</code>/<code>:datetime</code> column types.</p>
|
286
|
+
</li><li>
|
287
|
+
<p><strong>Reads</strong>: Support for <code>#find</code> on tables with
|
288
|
+
composite primary keys.</p>
|
289
|
+
</li><li>
|
290
|
+
<p><strong>Writes</strong>: Better handling of missing
|
291
|
+
<code>created_at</code>/<code>updated_at</code> columns on record
|
292
|
+
creation/updates.</p>
|
293
|
+
</li><li>
|
294
|
+
<p><strong>Traversal</strong>: Support for <code>has_many</code> relations
|
295
|
+
(only <code>belongs_to</code> is currently supported).</p>
|
296
|
+
</li><li>
|
297
|
+
<p><strong>Traversal</strong>: Support for self-referential foreign keys.</p>
|
298
|
+
</li><li>
|
299
|
+
<p><strong>Traversal</strong>: Support for multiple relations to the same
|
300
|
+
target model.</p>
|
301
|
+
</li></ul>
|
302
|
+
|
303
|
+
<h2 id="label-Contribution+-2F+Development">Contribution / Development</h2>
|
304
|
+
|
305
|
+
<p>Bug reports and pull requests are welcome on GitHub at <a
|
306
|
+
href="https://github.com/nestor-custodio/automodel-sqlserver">github.com/nestor-custodio/automodel-sqlserver</a>.</p>
|
307
|
+
|
308
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install
|
309
|
+
dependencies. Then, run <code>rake spec</code> to run the tests. You can
|
310
|
+
also run <code>bin/console</code> for an interactive prompt that will allow
|
311
|
+
you to experiment.</p>
|
312
|
+
|
313
|
+
<p>Linting is courtesy of <a
|
314
|
+
href="https://github.com/bbatsov/rubocop">Rubocop</a> and documentation is
|
315
|
+
built using <a href="https://yardoc.org/">Yard</a>. Neither is included in
|
316
|
+
the Gemspec; you'll need to install these locally (<code>gem install
|
317
|
+
rubocop yard</code>) to take advantage.</p>
|
318
|
+
|
319
|
+
<h2 id="label-License">License</h2>
|
320
|
+
|
321
|
+
<p>The gem is available as open source under the terms of the <a
|
322
|
+
href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
323
|
+
</div></div>
|
324
|
+
|
325
|
+
<div id="footer">
|
326
|
+
Generated on Wed Jun 20 18:16:08 2018 by
|
327
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
328
|
+
0.9.14 (ruby-2.4.4).
|
329
|
+
</div>
|
330
|
+
|
331
|
+
</div>
|
332
|
+
</body>
|
333
|
+
</html>
|