Simba computer scientist Mike Howard authored this blog post on N1QL data manipulation and ODBC connectivity for Simba Technologies partner Couchbase.

N1QL DML

N1QL data manipulation support makes it easy to insert, update, and delete JSON data, without the overhead of having to read the document first. These N1QL statements can perform an operation across an entire bucket with a single network request. N1QL queries are not bound by schema, and therefore can be used to manipulate data outside of schema constraints. Also, N1QL queries are not restricted to a single table, and are perfect for manipulating data across multiple tables simultaneously. The Simba Couchbase Driver for ODBC allows you to execute these queries directly through the driver.

INSERT

N1QL INSERT allows for the insert of a new JSON Document. While this method could be used for the simple task of adding a row to an existing table, it is particularly useful when adding data that does not match an existing schema. The ability to add non-schema data enables you to manipulate the schema: Add a document of existing type with new attributes, or add a document of new type to create new tables. And you’ll get new columns in the schema. However, you’ll have to resample the database (using SQL) to view any new non-schema data.

Using the gamesim-sample bucket as an example, say we wanted to add a “Bosses” feature to our game. Use a N1QL INSERT to create a Bosses table by adding a new document of type “boss”:

Resample with the driver to create a new boss table with this information. If we choose to extend our boss table to include experience points similar to the monster table, we can use N1QL INSERT to insert new documents into an existing table that do not match the table’s current schema:

 

Read the rest of Mike’s guest blog post at Couchbase.com.