|
| 1 | + |
| 2 | +/** meta is a factory used to define forward mapping for tables and columns. |
| 3 | + * Functions are called to create Meta objects that are stored with field mappings. |
| 4 | + * The Meta objects returned from these functions can be annotated with additional properties. |
| 5 | + * |
| 6 | + * Functions that can be used with fields: |
| 7 | + * meta.binary(lengthInBytes) doit callback.binary(lengthInBytes, lob, nullable); |
| 8 | + * meta.char(lengthInCharacters) doit callback.char(lengthInCharacters, lob, nullable); |
| 9 | + * meta.date() doit callback.date(nullable); |
| 10 | + * meta.datetime(fsp) doit callback.datetime(fsp, nullable); |
| 11 | + * meta.decimal(precision, scale) doit callback.decimal(precision, scale, nullable); |
| 12 | + * meta.double() doit callback.double(nullable); |
| 13 | + * meta.float() doit callback.float(nullable); |
| 14 | + * meta.integer(bits) doit callback.integer(bits, unsigned, nullable); |
| 15 | + * meta.interval(fsp) doit callback.interval(fsp, nullable); |
| 16 | + * meta.int synonym for integer doit callback.integer(bits, unsigned, nullable); |
| 17 | + * meta.number synonym for decimal doit callback.decimal(precision, scale, nullable); |
| 18 | + * meta.time(fsp) doit callback.time(fsp, nullable); |
| 19 | + * meta.timestamp(fsp) doit callback.timestamp(fsp, nullable); |
| 20 | + * meta.varchar(lengthInCharacters) doit callback.varchar(lengthInCharacters, lob, nullable); |
| 21 | + * meta.varbinary(lengthInBytes) doit callback.varbinary(lengthInBytes, lob, nullable); |
| 22 | + * meta.year() doit callback.year(nullable); |
| 23 | + * |
| 24 | + * Meta objects can be modified to include additional properties that apply to field mapping: |
| 25 | + * Meta.charset(name1, name2) character set and collation; applies to char and varchar types |
| 26 | + * Meta.hash() hash (only) index; applies to all indexable types |
| 27 | + * Meta.lob() large object; applies to varbinary and varchar |
| 28 | + * Meta.notNull() not null; applies to all types |
| 29 | + * Meta.primaryKey() primary key; applies to all primary key types |
| 30 | + * Meta.uniqueKey() unique key; applies to all indexable types |
| 31 | + * Meta.unsigned() unsigned; applies to integer types |
| 32 | + * |
| 33 | + * Examples: |
| 34 | + * tableMapping.mapField('id', meta.int(32).primaryKey().unsigned()) => id INT UNSIGNED PRIMARY KEY |
| 35 | + * tableMapping.mapField('name', meta.varchar(32).notNull()) => name VARCHAR(32) NOT NULL |
| 36 | + * tableMapping.mapField('ssn', meta.char(9).hash()) ==> ssn char(9) INDEX USING HASH |
| 37 | + * tableMapping.mapField('scan', meta.varchar(1024000).lob() ==> TEXT(1024000) |
| 38 | + * |
| 39 | + * Functions that can be used with tables: |
| 40 | + * meta.index([columnNames], optionalIndexName); |
| 41 | + * meta.primaryKey([columnNames]); |
| 42 | + * meta.uniqueKey([columnNames], optionalIndexName); |
| 43 | + * meta.hashKey([columnNames], optionalIndexName); |
| 44 | + * meta.orderedIndex([columnNames], optionalIndexName); |
| 45 | + * |
| 46 | + * Examples: |
| 47 | + * new TableMapping('a', meta.primaryKey(['b', 'c'])); specifies primary key over columns b and c |
| 48 | + * new TableMapping('a', meta.primaryKey(['b', 'c'])).hash; specifies hash-only primary key over columns b and c |
| 49 | + * new TableMapping('a', meta.uniqueKey('b')); specifies unique ordered key over column b |
| 50 | + * new TableMapping('a', meta.uniqueKey('b').hash()); specifies unique hash key over column b |
| 51 | + * new TableMapping('a', meta.index('b')); specifies ordered index over column b |
| 52 | + * new TableMapping('a', meta.hashKey('b')); specifies unique hash key over column b |
| 53 | + |
| 54 | + */ |
| 55 | +meta |
| 56 | + |
| 57 | +/** Create a new Meta object that holds meta information. This constructor function is private, |
| 58 | + * and can only be used by a method on meta. All Meta objects are defined with a doit function |
| 59 | + * which calls back a function specific to the type of the Meta. The callback may be used |
| 60 | + * to create table definitions. |
| 61 | + */ |
| 62 | +Meta(); |
| 63 | + |
| 64 | +/** Call back the caller based on the type of Meta. See above for method called based on type. |
| 65 | + * A Meta constructed via meta.year() will call callback.year with the nullable value as a parameter |
| 66 | + * and return the value to the caller of doit. |
| 67 | + */ |
| 68 | +doit(callback); |
| 69 | + |
| 70 | +/** Annotate a Meta with NOT NULL property. |
| 71 | + @return this; // allows fluent method chaining |
| 72 | + */ |
| 73 | +notNull(); |
| 74 | + |
| 75 | +/** Annotate a Meta with UNSIGNED property. |
| 76 | + @return this; // allows fluent method chaining |
| 77 | + */ |
| 78 | +unsigned(); |
| 79 | + |
| 80 | +/** Annotate a Meta with PRIMARY KEY property. |
| 81 | + @return this; // allows fluent method chaining |
| 82 | + */ |
| 83 | +primary(); |
| 84 | + |
| 85 | +/** Annotate a Meta with UNIQUE KEY property. |
| 86 | + * This annotation specifies an ordered index unless hash is also used. |
| 87 | + @return this; // allows fluent method chaining |
| 88 | + */ |
| 89 | +uniqueKey(); |
| 90 | +unique(); |
| 91 | + |
| 92 | +/** Annotate a Meta with USING HASH property. |
| 93 | + * When used with primaryKey or uniqueKey, this specifies that the index created uses a hash index (only). |
| 94 | + @return this; |
| 95 | + */ |
| 96 | +hash(); |
| 97 | + |
0 commit comments