Transform normal Javascript object to Mysql object. Only String, Number,
Date are supported.
344663
function toMysqlObj(obj) {
  if (obj === undefined || obj === null)
    return "NULL";

  switch (obj.constructor) {
  case Date:
    return `'${formatDate(obj)}'`;

  case String:
    return `'${obj.replace(/'/g, "''")}'`;

  case Number:
    return obj;

  default:
    throw new TypeError(`${util.inspect(obj)}`);
  }
}
1107617
function mysqlDate (input) {
	var date = new Date(input.getTime());
	date.setMinutes(date.getMinutes() + date.getTimezoneOffset());

	var y = date.getFullYear();
	var m = ('0' + (date.getMonth() + 1)).substr(-2);
	var d = ('0' + date.getDate()).substr(-2);
	var h = ('0' + date.getHours()).substr(-2);
	var i = ('0' + date.getMinutes()).substr(-2);
	var s = ('0' + date.getSeconds()).substr(-2);

	return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}
858038
public Object convertJavaFieldToSqlArgValue(Object fieldVal) throws SQLException {
		/*
		 * Limitation here. Some people may want to override the null with their own value in the converter but we
		 * currently don't allow that. Specifying a default value I guess is a better mechanism.
		 */
		if (fieldVal == null) {
			return null;
		} else {
			return fieldConverter.javaToSqlArg(this, fieldVal);
		}
	}
50735
function buildQueryString (obj) {
  var query = Object.keys(obj).reduce(function (acc, key) {
    return acc + '&' + querystring.escape(key) + '=' +
      querystring.escape(obj[key])
  }, '')
  return query.replace(/^&/, '?')
}
617709
def value_to_sql_str(v):
    
    if v is None:
        return 'null'

    if type(v) in (types.IntType, types.FloatType, types.LongType):
        return str(v)

    if type(v) in (types.StringType, types.UnicodeType):
        return "'%s'" %(v.replace(u"'", u"\\'"))

    if isinstance(v, datetime):
        return "'%s'" %(v.strftime("%Y-%m-%d %H:%M:%S"))

    if isinstance(v, date):
        return "'%s'" %(v.strftime("%Y-%m-%d"))

    return str(v)
1085303
function toSQLName(input) {
  return !input || _.isObject(input) || _.isArray(input) || _.isNaN(input) ? undefined :
    input.toString().toLowerCase()
      .replace(/\W+/g, " ")
      .trim()
      .replace(/\s+/g, "_")
      .replace(/_+/g, "_")
      .substring(0, 64);
}
827989
function columnsToSQL(columns) {
    return columns
        .map(column => {
            let str = exprToSQL(column.expr);

            if (column.as !== null) {
                str += ' AS ';
                if (column.as.match(/^[a-z_][0-9a-z_]*$/i)) str += identifierToSql(column.as);
                else str += '"' + column.as + '"';
            }

            return str;
        })
        .join(', ');
}
310835
def from_json(self, document):
        
        # The timestamp is optional (e.g., in cases where model definitions are
        # loaded from file).
        if 'timestamp' in document:
            timestamp = datetime.datetime.strptime(
                document['timestamp'],
                '%Y-%m-%dT%H:%M:%S.%f'
            )
        else:
            timestamp = None
        # Create handle for database object
        return ModelHandle(
            document['_id'],
            document['properties'],
            [AttributeDefinition.from_json(el) for el in document['parameters']],
            ModelOutputs.from_json(document['outputs']),
            timestamp=timestamp
        )
1142971
function(sql, val, callback) {
  let qry = (typeof sql === 'object') ? sql : mysql.format(sql, val);
  if (!callback && typeof val === 'function') callback = val; // Handle 2 parm scenario

  _pool.getConnection((err, conn) => {
    _pool.query(qry, (err, items, fields) => {
      if (err) return callback(err);

      conn.release();

      callback(err, items);
    });
  });
}
586690
function fromExtra(value, type) {
    const t = (type + '').toLowerCase();
    switch (t) {

        case 'number':
            return toNumberOrUndefined(value);
            break;

        case 'boolean':
            return toTrueOrUndefined(value);
            break;

        case 'objectarray':
            return toObjectArrayOrUndefined(value);
            break;

        case 'date':
            return toDate(value);
            break;

        case 'array':
            return toArrayOrUndefined(value);
            break;

        case 'object':
            return toObjectOrUndefined(value);
            break;

        case 'string':
        default:
            return toStringOrUndefined(value);
            break;
    }
}
1296537
def _raw_sql(self, values):
        """"""
        if isinstance(self.model._meta.pk, CharField):
            when_clauses = " ".join(
                [self._when("'{}'".format(x), y) for (x, y) in values]
            )
        else:
            when_clauses = " ".join([self._when(x, y) for (x, y) in values])
        table_name = self.model._meta.db_table
        primary_key = self.model._meta.pk.column
        return 'SELECT CASE {}."{}" {} ELSE 0 END'.format(
            table_name, primary_key, when_clauses
        )
51653
function mysqlBulkUpsert(model, data) {
  var mysql = require("mysql");
  var queries = ["SET AUTOCOMMIT = 0"];

  // Transform data
  _.each(data, function(d) {
    var query = "REPLACE INTO " + model.tableName + " ([[COLUMNS]]) VALUES (?)";
    query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));
    query = mysql.format(query, [ _.values(d) ]);
    queries.push(query);
  });

  // Create final output and format
  queries.push("COMMIT");
  queries.push("SET AUTOCOMMIT = 1");
  return queries.join("; ");
}
267007
def to_representation(self, value):
        """"""
        content_type = ContentType.objects.get_for_id(value)
        return "_".join(content_type.natural_key())
139459
def to_python(self, value):
        """"""
        cache = None
        if value is None:
            return None

        if isinstance(value, DataDescriptor):
            return value
        elif isinstance(value, dict):
            # Allow pre-hydrated data objects.
            cache = value
            try:
                value = cache['__id']
            except KeyError:
                raise ValidationError("dictionary must contain an '__id' element")
        elif not isinstance(value, int):
            raise ValidationError("field must be a DataDescriptor, data object primary key or dict")

        return DataDescriptor(value, self, cache)
1302205
def alchemyencoder(obj):
    """"""
    if isinstance(obj, datetime.date):
        return obj.isoformat()
    elif isinstance(obj, decimal.Decimal):
        return float(obj)
693800
def value_to_db(self, value):
        
        assert isinstance(value, six.integer_types)
        return str(value).encode("utf_8")
354437
def shell2json(s):
    """"""
    replace = {
        r'BinData\(.+?\)': '1',
        r'(new )?Date\(.+?\)': '1',
        r'Timestamp\(.+?\)': '1',
        r'ObjectId\(.+?\)': '1',
        r'DBRef\(.+?\)': '1',
        r'undefined': '1',
        r'MinKey': '1',
        r'MaxKey': '1',
        r'NumberLong\(.+?\)': '1',
        r'/.+?/\w*': '1'
    }

    for key, value in replace.items():
        s = re.sub(key, value, s)

    return s