Sample Application
Unresolved include directive in modules/hello-world/pages/sample-application.adoc - include::7.0@sdk:shared:partial$sample-application.adoc[]
Unresolved include directive in modules/hello-world/pages/sample-application.adoc - include::7.0@sdk:shared:partial$sample-application.adoc[]
Unresolved include directive in modules/hello-world/pages/sample-application.adoc - include::7.0@sdk:shared:partial$sample-application.adoc[]
Unresolved include directive in modules/hello-world/pages/sample-application.adoc - include::7.0@sdk:shared:partial$sample-application.adoc[]
Sample App Backend
The backend code shows Couchbase Node.js SDK in action with Query and Search, but also how to plug together all of the elements and build an application with Couchbase Server and the Node.js SDK.
Here’s the airport search code, which checks to see whether the search term for the query string is a three or four letter FAA or ICAO abbreviation, and if not searches for it as an airport name:
var qs;
if (searchTerm.length === 3) {
// FAA code
qs = `SELECT airportname from \`travel-sample\` WHERE faa = '${searchTerm.toUpperCase()}';`;
} else if (searchTerm.length === 4 &&
(searchTerm.toUpperCase() === searchTerm ||
searchTerm.toLowerCase() === searchTerm)) {
// ICAO code
qs = `SELECT airportname from \`travel-sample\` WHERE icao = '${searchTerm.toUpperCase()}';`;
} else {
// Airport name
qs = `SELECT airportname from \`travel-sample\` WHERE LOWER(airportname) LIKE '%${searchTerm.toLowerCase()}%';`;
}
let result, rows;
try {
result = await cluster.query(qs);
rows = result.rows;
} catch (error) {
console.error(error)
};
res.send({
data: rows,
context: [qs]
});
The index.js file also contains the functions for handling users, registration, and N1QL queries.
Unresolved include directive in modules/hello-world/pages/sample-application.adoc - include::7.0@sdk:shared:partial$sample-application.adoc[]
Unresolved include directive in modules/hello-world/pages/sample-application.adoc - include::7.0@sdk:shared:partial$sample-application.adoc[]