Update documents
This commit is contained in:
parent
cb1e720803
commit
5e5a9792ac
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/_book
|
||||
/node_modules
|
||||
/gitbook
|
||||
|
@ -660,29 +660,6 @@
|
||||
|
||||
<h1 id="advanced-usage">Advanced Usage</h1>
|
||||
<!-- toc -->
|
||||
<ul>
|
||||
<li><a href="#error-handling">Error Handling</a></li>
|
||||
<li><a href="#transactions">Transactions</a><ul>
|
||||
<li><a href="#a-specific-example">A Specific Example</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#sql-builder">SQL Builder</a><ul>
|
||||
<li><a href="#run-raw-sql">Run Raw SQL</a></li>
|
||||
<li><a href="#sqlrow-sqlrows">sql.Row & sql.Rows</a></li>
|
||||
<li><a href="#scan-sqlrows-in-iteration">Scan sql.Rows In Iteration</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#generic-database-interface-sqldb">Generic database interface sql.DB</a><ul>
|
||||
<li><a href="#connection-pool">Connection Pool</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#composite-primary-key">Composite Primary Key</a></li>
|
||||
<li><a href="#logger">Logger</a><ul>
|
||||
<li><a href="#customize-logger">Customize Logger</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- toc stop -->
|
||||
<h2 id="error-handling">Error Handling</h2>
|
||||
<p>After perform any operations, if there are any error happened, GORM will set it to <code>*DB</code>'s <code>Error</code> field</p>
|
||||
<pre><code class="lang-go"><span class="hljs-keyword">if</span> err := db.Where(<span class="hljs-string">"name = ?"</span>, <span class="hljs-string">"jinzhu"</span>).First(&user).Error; err != <span class="hljs-literal">nil</span> {
|
||||
@ -859,7 +836,7 @@ db.SetLogger(log.New(os.Stdout, <span class="hljs-string">"\r\n"</span
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Advanced Usage","level":"1.6","depth":1,"next":{"title":"Error Handling","level":"1.6.1","depth":2,"anchor":"#error-handling","path":"advanced.md","ref":"advanced.md#error-handling","articles":[]},"previous":{"title":"Callbacks","level":"1.5","depth":1,"path":"callbacks.md","ref":"callbacks.md","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"advanced.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Advanced Usage","level":"1.6","depth":1,"next":{"title":"Error Handling","level":"1.6.1","depth":2,"anchor":"#error-handling","path":"advanced.md","ref":"advanced.md#error-handling","articles":[]},"previous":{"title":"Callbacks","level":"1.5","depth":1,"path":"callbacks.md","ref":"callbacks.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"advanced.md","mtime":"2017-01-02T12:58:30.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
@ -660,15 +660,6 @@
|
||||
|
||||
<h1 id="associations">Associations</h1>
|
||||
<!-- toc -->
|
||||
<ul>
|
||||
<li><a href="#belongs-to">Belongs To</a></li>
|
||||
<li><a href="#has-one">Has One</a></li>
|
||||
<li><a href="#has-many">Has Many</a></li>
|
||||
<li><a href="#many-to-many">Many To Many</a></li>
|
||||
<li><a href="#polymorphism">Polymorphism</a></li>
|
||||
<li><a href="#association-mode">Association Mode</a></li>
|
||||
</ul>
|
||||
<!-- toc stop -->
|
||||
<h2 id="belongs-to">Belongs To</h2>
|
||||
<pre><code class="lang-go"><span class="hljs-comment">// `User` belongs to `Profile`, `ProfileID` is the foreign key</span>
|
||||
<span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> {
|
||||
@ -924,7 +915,7 @@ db.Model(&user).Association(<span class="hljs-string">"Languages"<
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Associations","level":"1.3.3","depth":2,"next":{"title":"Belongs To","level":"1.3.3.1","depth":3,"anchor":"#belongs-to","path":"associations.md","ref":"associations.md#belongs-to","articles":[]},"previous":{"title":"Conventions & Overriding","level":"1.3.2","depth":2,"anchor":"#conventions","path":"models.md","ref":"models.md#conventions","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"associations.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Associations","level":"1.3.3","depth":2,"next":{"title":"Belongs To","level":"1.3.3.1","depth":3,"anchor":"#belongs-to","path":"associations.md","ref":"associations.md#belongs-to","articles":[]},"previous":{"title":"Conventions & Overriding","level":"1.3.2","depth":2,"anchor":"#conventions","path":"models.md","ref":"models.md#conventions","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"associations.md","mtime":"2017-01-02T13:43:54.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
@ -660,14 +660,6 @@
|
||||
|
||||
<h1 id="callbacks">Callbacks</h1>
|
||||
<!-- toc -->
|
||||
<ul>
|
||||
<li><a href="#creating-an-object">Creating An Object</a></li>
|
||||
<li><a href="#updating-an-object">Updating An Object</a></li>
|
||||
<li><a href="#deleting-an-object">Deleting An Object</a></li>
|
||||
<li><a href="#querying-an-object">Querying An Object</a></li>
|
||||
<li><a href="#callback-examples">Callback Examples</a></li>
|
||||
</ul>
|
||||
<!-- toc stop -->
|
||||
<p>You could define callback methods to pointer of model struct, it will be called when creating, updating, querying, deleting, if any callback returns an error, gorm will stop future operations and rollback all changes.</p>
|
||||
<h3 id="creating-an-object">Creating An Object</h3>
|
||||
<p>Available Callbacks for creating</p>
|
||||
@ -781,7 +773,7 @@ If you want to use those changes in your callbacks, you need to run your SQL in
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Callbacks","level":"1.5","depth":1,"next":{"title":"Advanced Usage","level":"1.6","depth":1,"path":"advanced.md","ref":"advanced.md","articles":[{"title":"Error Handling","level":"1.6.1","depth":2,"anchor":"#error-handling","path":"advanced.md","ref":"advanced.md#error-handling","articles":[]},{"title":"Transactions","level":"1.6.2","depth":2,"anchor":"#transactions","path":"advanced.md","ref":"advanced.md#transactions","articles":[]},{"title":"Raw SQL & SQL Builder","level":"1.6.3","depth":2,"anchor":"#sql-builder","path":"advanced.md","ref":"advanced.md#sql-builder","articles":[]},{"title":"Generic database interface sql.DB","level":"1.6.4","depth":2,"anchor":"#generic-database-interface-sqldb","path":"advanced.md","ref":"advanced.md#generic-database-interface-sqldb","articles":[]},{"title":"Composite Primary Key","level":"1.6.5","depth":2,"anchor":"#compose-primary-key","path":"advanced.md","ref":"advanced.md#compose-primary-key","articles":[]},{"title":"Overriding Logger","level":"1.6.6","depth":2,"anchor":"#logger","path":"advanced.md","ref":"advanced.md#logger","articles":[]}]},"previous":{"title":"Associations","level":"1.4.6","depth":2,"anchor":"#associations","path":"crud.md","ref":"crud.md#associations","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"callbacks.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Callbacks","level":"1.5","depth":1,"next":{"title":"Advanced Usage","level":"1.6","depth":1,"path":"advanced.md","ref":"advanced.md","articles":[{"title":"Error Handling","level":"1.6.1","depth":2,"anchor":"#error-handling","path":"advanced.md","ref":"advanced.md#error-handling","articles":[]},{"title":"Transactions","level":"1.6.2","depth":2,"anchor":"#transactions","path":"advanced.md","ref":"advanced.md#transactions","articles":[]},{"title":"Raw SQL & SQL Builder","level":"1.6.3","depth":2,"anchor":"#sql-builder","path":"advanced.md","ref":"advanced.md#sql-builder","articles":[]},{"title":"Generic database interface sql.DB","level":"1.6.4","depth":2,"anchor":"#generic-database-interface-sqldb","path":"advanced.md","ref":"advanced.md#generic-database-interface-sqldb","articles":[]},{"title":"Composite Primary Key","level":"1.6.5","depth":2,"anchor":"#compose-primary-key","path":"advanced.md","ref":"advanced.md#compose-primary-key","articles":[]},{"title":"Overriding Logger","level":"1.6.6","depth":2,"anchor":"#logger","path":"advanced.md","ref":"advanced.md#logger","articles":[]}]},"previous":{"title":"Associations","level":"1.4.6","depth":2,"anchor":"#associations","path":"crud.md","ref":"crud.md#associations","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"callbacks.md","mtime":"2017-01-02T12:58:30.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
@ -743,7 +743,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Change Log","level":"1.8","depth":1,"previous":{"title":"Write Plugins","level":"1.7.2","depth":2,"anchor":"#write-plugins","path":"development.md","ref":"development.md#write-plugins","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"changelog.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Change Log","level":"1.8","depth":1,"previous":{"title":"Write Plugins","level":"1.7.2","depth":2,"anchor":"#write-plugins","path":"development.md","ref":"development.md#write-plugins","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"changelog.md","mtime":"2017-01-02T12:58:30.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
71
crud.html
71
crud.html
@ -660,75 +660,6 @@
|
||||
|
||||
<h1 id="crud-reading-and-writing-data">CRUD: Reading and Writing Data</h1>
|
||||
<!-- toc -->
|
||||
<ul>
|
||||
<li><a href="#create">Create</a><ul>
|
||||
<li><a href="#create-record">Create Record</a></li>
|
||||
<li><a href="#default-values">Default Values</a></li>
|
||||
<li><a href="#setting-primary-key-in-callbacks">Setting Primary Key In Callbacks</a></li>
|
||||
<li><a href="#extra-creating-option">Extra Creating option</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#query">Query</a><ul>
|
||||
<li><a href="#query-with-where-plain-sql">Query With Where (Plain SQL)</a></li>
|
||||
<li><a href="#query-with-where-struct-map">Query With Where (Struct & Map)</a></li>
|
||||
<li><a href="#query-with-not">Query With Not</a></li>
|
||||
<li><a href="#query-with-inline-condition">Query With Inline Condition</a></li>
|
||||
<li><a href="#query-with-or">Query With Or</a></li>
|
||||
<li><a href="#query-chains">Query Chains</a></li>
|
||||
<li><a href="#extra-querying-option">Extra Querying option</a></li>
|
||||
<li><a href="#firstorinit">FirstOrInit</a><ul>
|
||||
<li><a href="#attrs">Attrs</a></li>
|
||||
<li><a href="#assign">Assign</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#firstorcreate">FirstOrCreate</a><ul>
|
||||
<li><a href="#attrs">Attrs</a></li>
|
||||
<li><a href="#assign">Assign</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#select">Select</a></li>
|
||||
<li><a href="#order">Order</a></li>
|
||||
<li><a href="#limit">Limit</a></li>
|
||||
<li><a href="#offset">Offset</a></li>
|
||||
<li><a href="#count">Count</a></li>
|
||||
<li><a href="#group-having">Group & Having</a></li>
|
||||
<li><a href="#joins">Joins</a></li>
|
||||
<li><a href="#pluck">Pluck</a></li>
|
||||
<li><a href="#scan">Scan</a></li>
|
||||
<li><a href="#scopes">Scopes</a></li>
|
||||
<li><a href="#specifying-the-table-name">Specifying The Table Name</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#preloading-eager-loading">Preloading (Eager loading)</a><ul>
|
||||
<li><a href="#custom-preloading-sql">Custom Preloading SQL</a><ul>
|
||||
<li><a href="#nested-preloading">Nested Preloading</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#update">Update</a><ul>
|
||||
<li><a href="#update-all-fields">Update All Fields</a></li>
|
||||
<li><a href="#update-changed-fields">Update Changed Fields</a></li>
|
||||
<li><a href="#update-selected-fields">Update Selected Fields</a></li>
|
||||
<li><a href="#update-changed-fields-without-callbacks">Update Changed Fields Without Callbacks</a></li>
|
||||
<li><a href="#batch-updates">Batch Updates</a></li>
|
||||
<li><a href="#update-with-sql-expression">Update with SQL Expression</a></li>
|
||||
<li><a href="#change-updating-values-in-callbacks">Change Updating Values In Callbacks</a></li>
|
||||
<li><a href="#extra-updating-option">Extra Updating option</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#delete">Delete</a><ul>
|
||||
<li><a href="#batch-delete">Batch Delete</a></li>
|
||||
<li><a href="#soft-delete">Soft Delete</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#associations">Associations</a><ul>
|
||||
<li><a href="#skip-save-associations-when-creatingupdating">Skip Save Associations when creating/updating</a></li>
|
||||
<li><a href="#skip-save-associations-by-tag">Skip Save Associations by Tag</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- toc stop -->
|
||||
<h2 id="create">Create</h2>
|
||||
<h3 id="create-record">Create Record</h3>
|
||||
<pre><code class="lang-go">user := User{Name: <span class="hljs-string">"Jinzhu"</span>, Age: <span class="hljs-number">18</span>, Birthday: time.Now()}
|
||||
@ -1365,7 +1296,7 @@ db.Set(<span class="hljs-string">"gorm:save_associations"</span>, <spa
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"CRUD: Reading and Writing Data","level":"1.4","depth":1,"next":{"title":"Create","level":"1.4.1","depth":2,"anchor":"#create","path":"crud.md","ref":"crud.md#create","articles":[]},"previous":{"title":"Association Mode","level":"1.3.3.6","depth":3,"anchor":"#association-mode","path":"associations.md","ref":"associations.md#association-mode","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"crud.md","mtime":"2016-10-27T04:26:59.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"CRUD: Reading and Writing Data","level":"1.4","depth":1,"next":{"title":"Create","level":"1.4.1","depth":2,"anchor":"#create","path":"crud.md","ref":"crud.md#create","articles":[]},"previous":{"title":"Association Mode","level":"1.3.3.6","depth":3,"anchor":"#association-mode","path":"associations.md","ref":"associations.md#association-mode","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"crud.md","mtime":"2017-01-02T12:58:30.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
@ -660,27 +660,6 @@
|
||||
|
||||
<h1 id="database">Database</h1>
|
||||
<!-- toc -->
|
||||
<ul>
|
||||
<li><a href="#connecting-to-a-database">Connecting to a database</a><ul>
|
||||
<li><a href="#mysql">MySQL</a></li>
|
||||
<li><a href="#postgresql">PostgreSQL</a></li>
|
||||
<li><a href="#sqlite3">Sqlite3</a></li>
|
||||
<li><a href="#write-dialect-for-unsupported-databases">Write Dialect for unsupported databases</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#migration">Migration</a><ul>
|
||||
<li><a href="#auto-migration">Auto Migration</a></li>
|
||||
<li><a href="#has-table">Has Table</a></li>
|
||||
<li><a href="#create-table">Create Table</a></li>
|
||||
<li><a href="#drop-table">Drop table</a></li>
|
||||
<li><a href="#modifycolumn">ModifyColumn</a></li>
|
||||
<li><a href="#dropcolumn">DropColumn</a></li>
|
||||
<li><a href="#add-foreign-key">Add Foreign Key</a></li>
|
||||
<li><a href="#indexes">Indexes</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- toc stop -->
|
||||
<h2 id="connecting-to-a-database">Connecting to a database</h2>
|
||||
<p>In order to connect to a database, you need to import the database's driver first. For example:</p>
|
||||
<pre><code class="lang-go"><span class="hljs-keyword">import</span> _ <span class="hljs-string">"github.com/go-sql-driver/mysql"</span>
|
||||
@ -839,7 +818,7 @@ db.Model(&User{}).RemoveIndex(<span class="hljs-string">"idx_user_name&
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Database","level":"1.2","depth":1,"next":{"title":"Database Connection","level":"1.2.1","depth":2,"anchor":"#connecting-to-a-database","path":"database.md","ref":"database.md#connecting-to-a-database","articles":[]},"previous":{"title":"Getting Started with GORM","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"database.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Database","level":"1.2","depth":1,"next":{"title":"Database Connection","level":"1.2.1","depth":2,"anchor":"#connecting-to-a-database","path":"database.md","ref":"database.md#connecting-to-a-database","articles":[]},"previous":{"title":"Getting Started with GORM","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"database.md","mtime":"2017-01-02T12:58:30.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
@ -660,18 +660,6 @@
|
||||
|
||||
<h1 id="development">Development</h1>
|
||||
<!-- toc -->
|
||||
<ul>
|
||||
<li><a href="#architecture">Architecture</a></li>
|
||||
<li><a href="#write-plugins">Write Plugins</a><ul>
|
||||
<li><a href="#register-a-new-callback">Register a new callback</a></li>
|
||||
<li><a href="#delete-an-existing-callback">Delete an existing callback</a></li>
|
||||
<li><a href="#replace-an-existing-callback">Replace an existing callback</a></li>
|
||||
<li><a href="#register-callback-orders">Register callback orders</a></li>
|
||||
<li><a href="#pre-defined-callbacks">Pre-Defined Callbacks</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- toc stop -->
|
||||
<h2 id="architecture">Architecture</h2>
|
||||
<p>Gorm use chainable API, <code>*gorm.DB</code> is the bridge of chains, for each chain API, it will create a new relation.</p>
|
||||
<pre><code class="lang-go">db, err := gorm.Open(<span class="hljs-string">"postgres"</span>, <span class="hljs-string">"user=gorm dbname=gorm sslmode=disable"</span>)
|
||||
@ -784,7 +772,7 @@ db.Callback().RowQuery().Register(<span class="hljs-string">"publish:update
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Development","level":"1.7","depth":1,"next":{"title":"Architecture","level":"1.7.1","depth":2,"anchor":"#architecture","path":"development.md","ref":"development.md#architecture","articles":[]},"previous":{"title":"Overriding Logger","level":"1.6.6","depth":2,"anchor":"#logger","path":"advanced.md","ref":"advanced.md#logger","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"development.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Development","level":"1.7","depth":1,"next":{"title":"Architecture","level":"1.7.1","depth":2,"anchor":"#architecture","path":"development.md","ref":"development.md#architecture","articles":[]},"previous":{"title":"Overriding Logger","level":"1.6.6","depth":2,"anchor":"#logger","path":"advanced.md","ref":"advanced.md#logger","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"development.md","mtime":"2017-01-02T12:58:30.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
@ -85,6 +85,10 @@ func main() {
|
||||
|
||||
https://github.com/jinzhu/gorm/graphs/contributors
|
||||
|
||||
# Supporting the project
|
||||
|
||||
[](http://patreon.com/jinzhu)
|
||||
|
||||
## License
|
||||
|
||||
Released under the [MIT License](https://github.com/jinzhu/gorm/blob/master/License).
|
||||
|
@ -1,17 +1,13 @@
|
||||
{
|
||||
"title": "GORM Guide",
|
||||
"plugins": [
|
||||
"toc", "github", "edit-link"
|
||||
"github", "edit-link"
|
||||
],
|
||||
"pluginsConfig": {
|
||||
"fontsettings": {
|
||||
"theme": "night",
|
||||
"size": 2
|
||||
},
|
||||
"toc": {
|
||||
"addClass": true,
|
||||
"className": "toc"
|
||||
},
|
||||
"github": {
|
||||
"url": "https://github.com/jinzhu/gorm"
|
||||
},
|
||||
|
@ -731,6 +731,8 @@
|
||||
</ul>
|
||||
<h1 id="contributors">Contributors</h1>
|
||||
<p><a href="https://github.com/jinzhu/gorm/graphs/contributors" target="_blank">https://github.com/jinzhu/gorm/graphs/contributors</a></p>
|
||||
<h1 id="supporting-the-project">Supporting the project</h1>
|
||||
<p><a href="http://patreon.com/jinzhu" target="_blank"><img src="http://patreon_public_assets.s3.amazonaws.com/sized/becomeAPatronBanner.png" alt="http://patreon.com/jinzhu"></a></p>
|
||||
<h2 id="license">License</h2>
|
||||
<p>Released under the <a href="https://github.com/jinzhu/gorm/blob/master/License" target="_blank">MIT License</a>.</p>
|
||||
|
||||
@ -772,7 +774,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Getting Started with GORM","level":"1.1","depth":1,"next":{"title":"Database","level":"1.2","depth":1,"path":"database.md","ref":"database.md","articles":[{"title":"Database Connection","level":"1.2.1","depth":2,"anchor":"#connecting-to-a-database","path":"database.md","ref":"database.md#connecting-to-a-database","articles":[]},{"title":"Migration","level":"1.2.2","depth":2,"anchor":"#migration","path":"database.md","ref":"database.md#migration","articles":[]}]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"README.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Getting Started with GORM","level":"1.1","depth":1,"next":{"title":"Database","level":"1.2","depth":1,"path":"database.md","ref":"database.md","articles":[{"title":"Database Connection","level":"1.2.1","depth":2,"anchor":"#connecting-to-a-database","path":"database.md","ref":"database.md#connecting-to-a-database","articles":[]},{"title":"Migration","level":"1.2.2","depth":2,"anchor":"#migration","path":"database.md","ref":"database.md#migration","articles":[]}]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"README.md","mtime":"2017-01-02T13:55:47.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
19
models.html
19
models.html
@ -660,21 +660,6 @@
|
||||
|
||||
<h1 id="models">Models</h1>
|
||||
<!-- toc -->
|
||||
<ul>
|
||||
<li><a href="#model-definition">Model Definition</a></li>
|
||||
<li><a href="#conventions">Conventions</a><ul>
|
||||
<li><a href="#gormmodel-struct"><code>gorm.Model</code> struct</a></li>
|
||||
<li><a href="#table-name-is-the-pluralized-version-of-struct-name">Table name is the pluralized version of struct name</a></li>
|
||||
<li><a href="#change-default-tablenames">Change default tablenames</a></li>
|
||||
<li><a href="#column-name-is-the-snake-case-of-fields-name">Column name is the snake case of field's name</a></li>
|
||||
<li><a href="#field-id-as-primary-key">Field <code>ID</code> as primary key</a></li>
|
||||
<li><a href="#field-createdat-used-to-store-records-created-time">Field <code>CreatedAt</code> used to store record's created time</a></li>
|
||||
<li><a href="#use-updatedat-used-to-store-records-updated-time">Use <code>UpdatedAt</code> used to store record's updated time</a></li>
|
||||
<li><a href="#use-deletedat-to-store-records-deleted-time-if-field-exists">Use <code>DeletedAt</code> to store record's deleted time if field exists</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- toc stop -->
|
||||
<h2 id="model-definition">Model Definition</h2>
|
||||
<pre><code class="lang-go"><span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> {
|
||||
gorm.Model
|
||||
@ -749,7 +734,7 @@
|
||||
<h3 id="table-name-is-the-pluralized-version-of-struct-name">Table name is the pluralized version of struct name</h3>
|
||||
<pre><code class="lang-go"><span class="hljs-keyword">type</span> User <span class="hljs-keyword">struct</span> {} <span class="hljs-comment">// default table name is `users`</span>
|
||||
|
||||
<span class="hljs-comment">// set User's table name to be `profiles</span>
|
||||
<span class="hljs-comment">// set User's table name to be `profiles`</span>
|
||||
<span class="hljs-keyword">func</span> (User) TableName() <span class="hljs-keyword">string</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-string">"profiles"</span>
|
||||
}
|
||||
@ -855,7 +840,7 @@ db.Model(&user).Update(<span class="hljs-string">"name"</span>, <s
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Models","level":"1.3","depth":1,"next":{"title":"Model Definition","level":"1.3.1","depth":2,"anchor":"#model-definition","path":"models.md","ref":"models.md#model-definition","articles":[]},"previous":{"title":"Migration","level":"1.2.2","depth":2,"anchor":"#migration","path":"database.md","ref":"database.md#migration","articles":[]},"dir":"ltr"},"config":{"plugins":["toc","github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/jinzhu/gorm"},"toc":{"addClass":true,"className":"toc"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"night","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"models.md","mtime":"2016-10-27T02:32:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2016-10-27T04:34:17.895Z"},"basePath":".","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Models","level":"1.3","depth":1,"next":{"title":"Model Definition","level":"1.3.1","depth":2,"anchor":"#model-definition","path":"models.md","ref":"models.md#model-definition","articles":[]},"previous":{"title":"Migration","level":"1.2.2","depth":2,"anchor":"#migration","path":"database.md","ref":"database.md#migration","articles":[]},"dir":"ltr"},"config":{"plugins":["github","edit-link"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"fontsettings":{"theme":"night","family":"sans","size":2},"github":{"url":"https://github.com/jinzhu/gorm"},"edit-link":{"label":"Edit This Page","base":"https://github.com/jinzhu/gorm/edit/gh-pages/documents/"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"GORM Guide","gitbook":"*"},"file":{"path":"models.md","mtime":"2017-01-02T12:58:41.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-01-02T13:55:56.479Z"},"basePath":".","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user