5.3.3 Converter

Converter classes convert between JavaScript types and MySQL types. If the user supplies a JavaScript converter, it used to read and write to the database.

Converters have several purposes, including the following:

The ndb backend also uses converters to support SET and ENUM columns. (The mysql backend does not use these.)

A Converter class has the interface defined here:

function Converter() {}:

Converter.prototype = {
  "toDB"    : function(obj) {  },
  "fromDB"  : function(val) {  }
};

The Converter must implement the following two functions:

  1. toDB(obj): Convert an application object obj into a form that can be stored in the database.

  2. fromDB(val): Convert a value val read from the database into application object format.

Each function returns the result of the conversion.

Converter invocations are chained in the following ways: