不要怂,就是干,撸起袖子干!

lib_dialects_sqlite_query-interface.js.html 8.3 KB
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>lib&#x2F;dialects&#x2F;sqlite&#x2F;query-interface.js</title>
    <link rel="stylesheet" href="http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;3.8.0&#x2F;build&#x2F;cssgrids&#x2F;cssgrids-min.css">
    <link rel="stylesheet" href="..&#x2F;assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="..&#x2F;assets/css/main.css" id="site_styles">
    <link rel="shortcut icon" type="image/png" href="..&#x2F;assets/favicon.png">
    <script src="http:&#x2F;&#x2F;yui.yahooapis.com&#x2F;combo?3.8.0&#x2F;build&#x2F;yui&#x2F;yui-min.js"></script>
</head>
<body class="yui3-skin-sam">

<div id="doc">
    <div id="hd" class="yui3-g header">
        <div class="yui3-u-3-4">
            
                <h1><img src="..&#x2F;assets/css/logo.png" title=""></h1>
            
        </div>
        <div class="yui3-u-1-4 version">
            <em>API Docs for: </em>
        </div>
    </div>
    <div id="bd" class="yui3-g">

        <div class="yui3-u-1-4">
            <div id="docs-sidebar" class="sidebar apidocs">
                <div id="api-list">
    <h2 class="off-left">APIs</h2>
    <div id="api-tabview" class="tabview">
        <ul class="tabs">
            <li><a href="#api-classes">Classes</a></li>
            <li><a href="#api-modules">Modules</a></li>
        </ul>

        <div id="api-tabview-filter">
            <input type="search" id="api-filter" placeholder="Type to filter APIs">
        </div>

        <div id="api-tabview-panel">
            <ul id="api-classes" class="apis classes">
            
                <li><a href="..&#x2F;classes/QueryInterface.html">QueryInterface</a></li>
            
                <li><a href="..&#x2F;classes/Sequelize.html">Sequelize</a></li>
            
            </ul>

            <ul id="api-modules" class="apis modules">
            
                <li><a href="..&#x2F;modules/Sequelize.html">Sequelize</a></li>
            
            </ul>
        </div>
    </div>
</div>

            </div>
        </div>
        <div class="yui3-u-3-4">
                <div id="api-options">
        Show:
        <label for="api-show-inherited">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </div>


            <div class="apidocs">
                <div id="docs-main">
                    <div class="content">
                        <h1 class="file-heading">File: lib&#x2F;dialects&#x2F;sqlite&#x2F;query-interface.js</h1>

<div class="file">
    <pre class="code prettyprint linenums">
var Utils = require(&quot;..&#x2F;..&#x2F;utils&quot;)

&#x2F;**
 Returns an object that treats SQLite&#x27;s inabilities to do certain queries.

 @class QueryInterface
 @static
 *&#x2F;
var QueryInterface = module.exports = {
  &#x2F;**
    A wrapper that fixes SQLite&#x27;s inability to remove columns from existing tables.
    It will create a backup of the table, drop the table afterwards and create a
    new table with the same name but without the obsolete column.

    @method removeColumn
    @for    QueryInterface

    @param  {String} tableName     The name of the table.
    @param  {String} attributeName The name of the attribute that we want to remove.
    @param  {CustomEventEmitter} emitter       The EventEmitter from outside.
    @param  {Function} queryAndEmit  The function from outside that triggers some events to get triggered.

    @since 1.6.0
   *&#x2F;
  removeColumn: function(tableName, attributeName, emitter, queryAndEmit) {
    this.describeTable(tableName).complete(function(err, fields) {
      if (err) {
        emitter.emit(&#x27;error&#x27;, err)
      } else {
        delete fields[attributeName]

        var sql        = this.QueryGenerator.removeColumnQuery(tableName, fields)
          , subQueries = sql.split(&#x27;;&#x27;).filter(function(q) { return q !== &#x27;&#x27; })

        QueryInterface.execMultiQuery.call(this, subQueries, &#x27;removeColumn&#x27;, emitter, queryAndEmit)
      }
    }.bind(this))
  },

  &#x2F;**
    A wrapper that fixes SQLite&#x27;s inability to change columns from existing tables.
    It will create a backup of the table, drop the table afterwards and create a
    new table with the same name but with a modified version of the respective column.

    @method changeColumn
    @for    QueryInterface

    @param  {String} tableName The name of the table.
    @param  {Object} attributes An object with the attribute&#x27;s name as key and it&#x27;s options as value object.
    @param  {CustomEventEmitter} emitter The EventEmitter from outside.
    @param  {Function} queryAndEmit The function from outside that triggers some events to get triggered.

    @since 1.6.0
   *&#x2F;
  changeColumn: function(tableName, attributes, emitter, queryAndEmit) {
    var attributeName = Utils._.keys(attributes)[0]

    this.describeTable(tableName).complete(function(err, fields) {
      if (err) {
        emitter.emit(&#x27;error&#x27;, err)
      } else {
        fields[attributeName] = attributes[attributeName]

        var sql        = this.QueryGenerator.removeColumnQuery(tableName, fields)
          , subQueries = sql.split(&#x27;;&#x27;).filter(function(q) { return q !== &#x27;&#x27; })

        QueryInterface.execMultiQuery.call(this, subQueries, &#x27;changeColumn&#x27;, emitter, queryAndEmit)
      }
    }.bind(this))
  },

  &#x2F;**
    A wrapper that fixes SQLite&#x27;s inability to rename columns from existing tables.
    It will create a backup of the table, drop the table afterwards and create a
    new table with the same name but with a renamed version of the respective column.

    @method renameColumn
    @for    QueryInterface

    @param  {String} tableName The name of the table.
    @param  {String} attrNameBefore The name of the attribute before it was renamed.
    @param  {String} attrNameAfter The name of the attribute after it was renamed.
    @param  {CustomEventEmitter} emitter The EventEmitter from outside.
    @param  {Function} queryAndEmit The function from outside that triggers some events to get triggered.

    @since 1.6.0
   *&#x2F;
  renameColumn: function(tableName, attrNameBefore, attrNameAfter, emitter, queryAndEmit) {
    this.describeTable(tableName).complete(function(err, fields) {
      if (err) {
        emitter.emit(&#x27;error&#x27;, err)
      } else {
        fields[attrNameAfter] = Utils._.clone(fields[attrNameBefore])
        delete fields[attrNameBefore]

        var sql        = this.QueryGenerator.renameColumnQuery(tableName, attrNameBefore, attrNameAfter, fields)
          , subQueries = sql.split(&#x27;;&#x27;).filter(function(q) { return q !== &#x27;&#x27; })

        QueryInterface.execMultiQuery.call(this, subQueries, &#x27;renameColumn&#x27;, emitter, queryAndEmit)
      }
    }.bind(this))
  },

  execMultiQuery: function(queries, methodName, emitter, queryAndEmit) {
    var chainer = new Utils.QueryChainer()

    queries.splice(0, queries.length - 1).forEach(function(query) {
      chainer.add(this.sequelize, &#x27;query&#x27;, [query + &quot;;&quot;, null, { raw: true }])
    }.bind(this))

    chainer
      .runSerially()
      .complete(function(err) {
        if (err) {
          emitter.emit(methodName, err)
          emitter.emit(&#x27;error&#x27;, err)
        } else {
          queryAndEmit.call(this, queries.splice(queries.length - 1)[0], methodName, {}, emitter)
        }
      }.bind(this))
  }
}

    </pre>
</div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="..&#x2F;assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="..&#x2F;assets/js/yui-prettify.js"></script>
<script src="..&#x2F;assets/../api.js"></script>
<script src="..&#x2F;assets/js/api-filter.js"></script>
<script src="..&#x2F;assets/js/api-list.js"></script>
<script src="..&#x2F;assets/js/api-search.js"></script>
<script src="..&#x2F;assets/js/apidocs.js"></script>
</body>
</html>