Skip to content

Commit d27bfe1

Browse files
committed
merge latest nodejs-adapter into 7.4
2 parents c88baff + d04018d commit d27bfe1

File tree

131 files changed

+3442
-773
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+3442
-773
lines changed

storage/ndb/nodejs/.bzrignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ test/disabled-tests.conf
99
config.gypi
1010
config.waf
1111
benchmark_logs
12+
node_modules
13+
build
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+

storage/ndb/nodejs/API-documentation/Mynode

+13
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ openSession(Properties, mappings, [callback], [...]);
117117
getOpenSessionFactories();
118118

119119

120+
/** Close all open SessionFactories
121+
*
122+
* This method closes all SessionFactories.
123+
* Because a SessionFactory likely uses an open TCP connection with registered
124+
* callbacks, Node.JS will generally not exit while any SessionFactory is
125+
* still open.
126+
*
127+
* @param callback function called after all SessionFactories are closed
128+
* @return a promise
129+
*/
130+
closeAllOpenSessionFactories();
131+
132+
120133
// The following functions are part of the public API but are not intended for
121134
// application use. They form part of the contract between mynode and
122135
// SessionFactory.

storage/ndb/nodejs/API-documentation/Query

+30-4
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,51 @@
143143
*/
144144
function between(Object parameterOrLiteral, Object parameterOrLiteral);
145145

146+
/** isNull represents null comparison of a property.
147+
* @return QueryPredicate
148+
* IMMEDIATE
149+
*/
150+
function isNull();
151+
152+
/** isNotNull represents not-null comparison of a property.
153+
* @return QueryPredicate
154+
* IMMEDIATE
155+
*/
156+
function isNotNull();
157+
146158
/** QueryPredicate represents the result of comparing a query field to a
147159
* parameter. QueryPredicate can be used as the filter for a query or can be
148-
* combined with other QueryPredicates using boolean functions 'and', 'or',
149-
* and unary function 'not'.
160+
* combined with other QueryPredicates using functions 'and', 'or',
161+
* 'andNot', 'orNot', and 'not'.
150162
*/
151163
function QueryPredicate();
152164

153-
/** and represents the and condition joining this QueryPredicate with another.
165+
/** and represents the 'and' condition joining this QueryPredicate with another.
154166
* @return QueryPredicate
155167
* IMMEDIATE
156168
*/
157169
function and(QueryPredicate other);
158170

159-
/** or represents the or condition joining this QueryPredicate with another.
171+
/** andNot represents the 'and' condition joining this QueryPredicate with
172+
* the negation of another.
173+
* @return QueryPredicate
174+
* IMMEDIATE
175+
*/
176+
function andNot(QueryPredicate other);
177+
178+
/** or represents the 'or' condition joining this QueryPredicate with another.
160179
* @return QueryPredicate
161180
* IMMEDIATE
162181
*/
163182
function or(QueryPredicate other);
164183

184+
/** orNot represents the 'or' condition joining this QueryPredicate with
185+
* the negation of another.
186+
* @return QueryPredicate
187+
* IMMEDIATE
188+
*/
189+
function orNot(QueryPredicate other);
190+
165191
/** not represents the negation of this QueryPredicate.
166192
* @return QueryPredicate
167193
* IMMEDIATE

storage/ndb/nodejs/API-documentation/Session

+9-16
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
* If keys cannot identify the primary key, property names corresponding to
2020
* unique key columns will be used. If no complete primary or unique key
2121
* properties are found, an error is reported.
22+
* If the first parameter is a Projection, the find operation will return
23+
* the object corresponding to the key. Additionally, the properties
24+
* defined in the projection as relationship properties will be fetched,
25+
* recursively.
2226
*
2327
* For multi-column primary or unique keys, all key fields must be set.
2428
*
25-
* The returned object will be loaded based on the mapping and the current
26-
* values in the database.
29+
* The returned object will be loaded based on the mapping, the Projection,
30+
* and the current values in the database.
2731
*
2832
* This function returns a promise. On success, the promise will be fulfilled
2933
* with the found object. The optional callback receives an error value and the
@@ -32,15 +36,16 @@
3236
* the found instance value.
3337
*
3438
* @method find
35-
* @param constructor the constructor function of a mapped domain object
39+
* @param constructorOrProjection the constructor function of a mapped domain object
40+
* or a Projection object.
3641
* @param keys the instance to find in the database
3742
* @param callback function to be called when operation has completed,
3843
* with parameters:
3944
* err: the node.js Error object
4045
* instance: the domain model object or null if not found
4146
* @return promise
4247
*/
43-
find(Function constructor, Object keys, [callback], [...]);
48+
find(Function constructorOrProjection, Object keys, [callback], [...]);
4449

4550
/** Find a specific instance based on primary or unique key value.
4651
* See other variant for semantics.
@@ -494,18 +499,6 @@ listTables(databaseName, callback);
494499
getTableMetadata(databaseName, tableName, callback);
495500
}
496501

497-
/** Use the projection for find and query operations on the domain object.
498-
* projection:= {constructor: domainObject,
499-
* fields: [field, field...],
500-
* relationships: [relationship, relationship...]}
501-
* The domain object must be mapped and will be validated by this function.
502-
* If fields is omitted, all fields in the mapping will be fetched.
503-
* If relationships is omitted, no relationships in the mapping will be fetched.
504-
* This method returns a promise and can use a callback.
505-
* ASYNC
506-
*/
507-
useProjection(projection, callback);
508-
509502
/*
510503
* Users may find useful a "user" property of session and batch.
511504
* The mynode implementation will not ever define a property called "user".

storage/ndb/nodejs/API-documentation/SessionFactory

+20
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,23 @@ close(function(error));
6060
@param converterObject is as defined in Converter
6161
*/
6262
registerTypeConverter(typeName, converterObject);
63+
64+
/** db(): get a new db object bound to a database that supports "easy to use"
65+
* insert and find operations without defining tables or mappings. Each operation
66+
* is executed in auto-commit mode using a new session.
67+
* IMMEDIATE
68+
* @param databaseName is the name of the database to use; default is session factory's database
69+
* @return the db object
70+
*/
71+
db db(databaseName);
72+
73+
/** mapTable(): associate a TableMapping with a database and table name.
74+
* If a table is needed for an operation and the table does not exist, use the TableMapping
75+
* meta to define the table. The database and table name are taken from the TableMapping.
76+
* If the TableMapping does not include the datbase, use the default database for this session
77+
* factory. If there is already a TableMapping with the same database and table, it is replaced.
78+
* IMMEDIATE
79+
* @param tableMapping is the mapping to associate with the database and table in this session factory
80+
*/
81+
mapTable(tableMapping);
82+

storage/ndb/nodejs/API-documentation/TableMapping

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ TableMapping = {
2424
Can also be called "field",
2525
and can also hold a single FieldMapping.
2626
@property fields @type Array */
27-
error : '' /** Reports errors during construction */
27+
error : '', /** Reports errors during construction */
28+
mappedFieldNames : [], /** mapped field names (excluded from sparse field handling) */
29+
meta : []
2830

2931
};
3032

@@ -43,8 +45,13 @@ FieldMapping = {
4345
@type String */
4446
persistent : true, /** Whether this field should be stored in database.
4547
@type Boolean @default true */
46-
converter : null /** Converter class to use with this field
48+
converter : null, /** Converter class to use with this field
4749
@type Converter @default null */
50+
sparseFieldNames: null, /** sparse field names to store in this column
51+
@type array @default null */
52+
meta : undefined /** meta for forward table definition
53+
@see Meta for usage
54+
@type Meta @default undefined */
4855
};
4956

5057

storage/ndb/nodejs/Adapter/adapter_config.js

+36-24
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,63 @@
1919
*/
2020

2121

22-
global.path = require("path");
23-
global.fs = require("fs");
24-
global.assert = require("assert");
25-
global.util = require("util");
26-
27-
global.adapter_dir = __dirname;
28-
global.parent_dir = path.dirname(adapter_dir);
29-
global.api_dir = path.join(adapter_dir, "api");
30-
global.spi_dir = path.join(adapter_dir, "impl");
31-
global.spi_doc_dir = path.join(spi_dir, "SPI-documentation");
32-
global.api_doc_dir = path.join(parent_dir, "API-documentation");
33-
global.converters_dir = path.join(parent_dir, "Converters");
34-
35-
global.spi_module = path.join(spi_dir, "SPI.js");
36-
global.api_module = path.join(api_dir, "mynode.js");
37-
global.udebug_module = path.join(api_dir, "unified_debug.js");
38-
global.unified_debug = require(udebug_module);
22+
var path = require("path");
23+
var fs = require("fs");
24+
var mynode, parent_dir, udebug_module;
25+
26+
mynode = {};
27+
mynode.fs = {};
28+
parent_dir = path.dirname(__dirname);
29+
30+
mynode.fs.adapter_dir = __dirname;
31+
mynode.fs.api_dir = path.join(mynode.fs.adapter_dir, "api");
32+
mynode.fs.spi_dir = path.join(mynode.fs.adapter_dir, "impl");
33+
34+
mynode.fs.spi_doc_dir = path.join(mynode.fs.spi_dir, "SPI-documentation");
35+
mynode.fs.api_doc_dir = path.join(parent_dir, "API-documentation");
36+
mynode.fs.backend_doc_dir = path.join(parent_dir, "Backend-documentation");
37+
mynode.fs.converters_dir = path.join(parent_dir, "Converters");
38+
39+
mynode.fs.spi_module = path.join(mynode.fs.spi_dir, "SPI.js");
40+
mynode.fs.api_module = path.join(mynode.fs.api_dir, "mynode.js");
41+
42+
mynode.fs.suites_dir = path.join(parent_dir, "test");
43+
mynode.fs.samples_dir = path.join(parent_dir, "samples");
44+
45+
udebug_module = path.join(mynode.fs.api_dir, "unified_debug.js");
3946

4047

4148
/* Find the build directory */
42-
var build1 = path.join(spi_dir, "build");
49+
var build1 = path.join(mynode.fs.spi_dir, "build");
4350
var build2 = path.join(parent_dir, "build");
4451
var existsSync = fs.existsSync || path.existsSync;
4552

4653
if(existsSync(path.join(build1, "Release", "ndb_adapter.node"))) {
47-
global.build_dir = path.join(build1, "Release");
54+
mynode.fs.build_dir = path.join(build1, "Release");
4855
}
4956
else if(existsSync(path.join(build2, "Release", "ndb_adapter.node"))) {
50-
global.build_dir = path.join(build2, "Release");
57+
mynode.fs.build_dir = path.join(build2, "Release");
5158
}
5259
else if(existsSync(path.join(build1, "Debug", "ndb_adapter.node"))) {
53-
global.build_dir = path.join(build1, "Debug");
60+
mynode.fs.build_dir = path.join(build1, "Debug");
5461
}
5562
else if(existsSync(path.join(build2, "Debug", "ndb_adapter.node"))) {
56-
global.build_dir = path.join(build2, "Debug");
63+
mynode.fs.build_dir = path.join(build2, "Debug");
5764
}
5865

5966
/* Some compatibility with older versions of node */
6067
if(typeof global.setImmediate !== 'function') {
6168
global.setImmediate = process.nextTick;
6269
}
6370

71+
/* Export the filesystem config */
72+
module.exports = mynode.fs;
6473

74+
/* Also make it available globally */
75+
if(!global.mynode) { global.mynode = {} };
76+
global.mynode.fs = mynode.fs;
6577

66-
67-
78+
/* And export unified_debug globally */
79+
global.unified_debug = require(udebug_module);
6880

6981

storage/ndb/nodejs/Adapter/api/Batch.js

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
02110-1301 USA
1919
*/
2020

21-
/*global unified_debug */
22-
2321
"use strict";
2422

2523
var userContext = require("./UserContext.js"),

0 commit comments

Comments
 (0)