Company
Date Published
Author
Sergey Avseyev, SDK Engineer, Couchbase
Word count
677
Language
English
Hacker News points
None

Summary

N1QL features have been added to the Ruby SDK, allowing developers to work with structured queries in Couchbase. The library does not provide an ODM or high-level abstraction, but everything else is possible. To use N1QL, developers need to establish a connection to the bucket using `Couchbase.connect`, and then call the `query` method on the bucket object, passing a string in N1QL. The response from the server is returned as a hash with :rows and :meta keys. Developers can create primary indexes for their data using the `CREATE PRIMARY INDEX` query, and fetch documents by their keys or use conditions. To make examples simpler, developers can use functions to strip metadata fields and extract just values. The library raises a `Couchbase::Error::Query` exception if there is an issue with the query. Developers can explore the structure of the sample database further, answer practical questions, and even create custom queries using joins and conditions.