lib/adapter.js
function (connectionName, table, cb) {
            if (LOG_DEBUG) {
                console.log("BEGIN describe");
            }
            var connectionObject = connections[connectionName];
            var collection = connectionObject.collections[table];

            if (!collection) {
                return cb(util.format('Unknown collection `%s` in connection `%s`', collectionName, connectionName));
            }

            var queries = [];
            queries[0] = "SELECT COLUMN_NAME, DATA_TYPE, NULLABLE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '" + table + "'";
            queries[1] = "SELECT index_name,COLUMN_NAME FROM user_ind_columns WHERE table_name = '" + table + "'";
            queries[2] = "SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner "
                    + "FROM all_constraints cons, all_cons_columns cols WHERE cols.table_name = '" + table
                    + "' AND cons.constraint_type = 'P' AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner "
                    + "ORDER BY cols.table_name, cols.position";

            
            // Run Query
            connectionObject.pool.getConnection(
                    function (err, connection)
                    {
                        if (err) {
                            handleQueryError(err, 'describe');
                            return;
                        }
                        if (LOG_QUERIES) {
                            console.log('Executing query: ' + queries[0]);
                        }
                        connection.execute(queries[0], {}, {outFormat: oracledb.OBJECT}, function __SCHEMA__(err, result) {

                            if (err) {
                                /* Release the connection back to the connection pool */
                                doRelease(connection);
                                return cb(handleQueryError(err, 'describe'));
                            }

                            var schema = result.rows;
                            if (LOG_QUERIES) {
                                console.log('Executing query: ' + queries[1]);
                            }
                            connection.execute(queries[1], {}, {outFormat: oracledb.OBJECT}, function __DEFINE__(err, result) {

                                if (err) {
                                    /* Release the connection back to the connection pool */
                                    doRelease(connection);
                                    return cb(handleQueryError(err, 'describe'));
                                }

                                var indexes = result.rows;

                                if (LOG_QUERIES) {
                                    console.log('Executing query: ' + queries[2]);
                                }
                                connection.execute(queries[2], {}, {outFormat: oracledb.OBJECT}, function __DEFINE__(err, result) {

                                    if (err) {
                                        /* Release the connection back to the connection pool */
                                        doRelease(connection);
                                        return cb(handleQueryError(err, 'describe'));
                                    }

                                    var tablePrimaryKeys = result.rows;
                                    if (schema.length === 0) {
                                        doRelease(connection);
                                        return cb();
                                    }

                                    // Loop through Schema and attach extra attributes
                                    schema.forEach(function (attribute) {
                                        tablePrimaryKeys.forEach(function (pk) {
                                            // Set Primary Key Attribute
                                            if (attribute.COLUMN_NAME === pk.COLUMN_NAME) {
                                                attribute.primaryKey = true;
                                                // If also a number set auto increment attribute
                                                if (attribute.DATA_TYPE === 'NUMBER') {
                                                    attribute.autoIncrement = true;
                                                }
                                            }
                                        });
                                        // Set Unique Attribute
                                        if (attribute.NULLABLE === 'N') {
                                            attribute.required = true;
                                        }

                                    });
                                    // Loop Through Indexes and Add Properties
                                    indexes.forEach(function (index) {
                                        schema.forEach(function (attribute) {
                                            if (attribute.COLUMN_NAME === index.COLUMN_NAME)
                                            {
                                                attribute.indexed = true;
                                            }
                                        });
                                    });
                                    // Convert mysql format to standard javascript object

                                    //var normalizedSchema = sql.normalizeSchema(schema, collection.attributes);
                                    // Set Internal Schema Mapping
                                    //collection.schema = normalizedSchema;

                                    /* Release the connection back to the connection pool */
                                    doRelease(connection);
                                    // TODO: check that what was returned actually matches the cache
                                    cb(null, schema);

                                });

                            });

                        });
                    });

        }
function (connectionName, table, cb) {
            if (LOG_DEBUG) {
                console.log("BEGIN describe");
            }
            var connectionObject = connections[connectionName];
            var collection = connectionObject.collections[table];

            if (!collection) {
                return cb(util.format('Unknown collection `%s` in connection `%s`', collectionName, connectionName));
            }

            var queries = [];
            queries[0] = "SELECT COLUMN_NAME, DATA_TYPE, NULLABLE FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '" + table + "'";
            queries[1] = "SELECT index_name,COLUMN_NAME FROM user_ind_columns WHERE table_name = '" + table + "'";
            queries[2] = "SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner "
                    + "FROM all_constraints cons, all_cons_columns cols WHERE cols.table_name = '" + table
                    + "' AND cons.constraint_type = 'P' AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner "
                    + "ORDER BY cols.table_name, cols.position";

            
            // Run Query
            connectionObject.pool.getConnection(
                    function (err, connection)
                    {
                        if (err) {
                            handleQueryError(err, 'describe');
                            return;
                        }
                        if (LOG_QUERIES) {
                            console.log('Executing query: ' + queries[0]);
                        }
                        connection.execute(queries[0], {}, {outFormat: oracledb.OBJECT}, function __SCHEMA__(err, result) {

                            if (err) {
                                /* Release the connection back to the connection pool */
                                doRelease(connection);
                                return cb(handleQueryError(err, 'describe'));
                            }

                            var schema = result.rows;
                            if (LOG_QUERIES) {
                                console.log('Executing query: ' + queries[1]);
                            }
                            connection.execute(queries[1], {}, {outFormat: oracledb.OBJECT}, function __DEFINE__(err, result) {

                                if (err) {
                                    /* Release the connection back to the connection pool */
                                    doRelease(connection);
                                    return cb(handleQueryError(err, 'describe'));
                                }

                                var indexes = result.rows;

                                if (LOG_QUERIES) {
                                    console.log('Executing query: ' + queries[2]);
                                }
                                connection.execute(queries[2], {}, {outFormat: oracledb.OBJECT}, function __DEFINE__(err, result) {

                                    if (err) {
                                        /* Release the connection back to the connection pool */
                                        doRelease(connection);
                                        return cb(handleQueryError(err, 'describe'));
                                    }

                                    var tablePrimaryKeys = result.rows;
                                    if (schema.length === 0) {
                                        doRelease(connection);
                                        return cb();
                                    }

                                    // Loop through Schema and attach extra attributes
                                    schema.forEach(function (attribute) {
                                        tablePrimaryKeys.forEach(function (pk) {
                                            // Set Primary Key Attribute
                                            if (attribute.COLUMN_NAME === pk.COLUMN_NAME) {
                                                attribute.primaryKey = true;
                                                // If also a number set auto increment attribute
                                                if (attribute.DATA_TYPE === 'NUMBER') {
                                                    attribute.autoIncrement = true;
                                                }
                                            }
                                        });
                                        // Set Unique Attribute
                                        if (attribute.NULLABLE === 'N') {
                                            attribute.required = true;
                                        }

                                    });
                                    // Loop Through Indexes and Add Properties
                                    indexes.forEach(function (index) {
                                        schema.forEach(function (attribute) {
                                            if (attribute.COLUMN_NAME === index.COLUMN_NAME)
                                            {
                                                attribute.indexed = true;
                                            }
                                        });
                                    });
                                    // Convert mysql format to standard javascript object

                                    //var normalizedSchema = sql.normalizeSchema(schema, collection.attributes);
                                    // Set Internal Schema Mapping
                                    //collection.schema = normalizedSchema;

                                    /* Release the connection back to the connection pool */
                                    doRelease(connection);
                                    // TODO: check that what was returned actually matches the cache
                                    cb(null, schema);

                                });

                            });

                        });
                    });

        }
Return attributes - OK