Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(binary uuids): implement binary(16) uuids for cash table #152

Merged
merged 1 commit into from
Mar 23, 2016

Commits on Mar 23, 2016

  1. feat(binary uuids): implement binary(16) uuids

    This commit implements a proof-of-concept binary UUID storage scheme for
    the cash module.  The integration tests have been updated accordingly.
    
    **Overview**
    The introduction of binary uuids means that a little more work must be
    done in the controllers and sql to insert/retrieve data.  Some commands
    in Node and SQL have been added to ease this process.  I'll document
    these differences as `before` and `after` scenarios.
    
    READ
    
    Before:
    ```sql
    SELECT uuid FROM table;
    ```
    
    After:
    ```sql
    SELECT BUID(uuid) AS uuid FROM table;
    ```
    **Note**: it is important to alias the column with `AS` in order to
    preserve the property name `uuid`.  The command `BUID()` has been added
    to our MySQL database instance to convert binary uuids into hexadecimal
    uuids.
    
    WRITE
    
    Before:
    ```js
    var insertSql = 'INSERT INTO table SET ?;';
    var updateSql = 'UPDATE table SET ? WHERE uuid = ?;';
    
    var data = {
      uuid : /** some uuid */,
      /* other properties ... */
    };
    
    db.exec(insertSql, [ data ]).then(/* ... */).catch(/* .. */);
    db.exec(updateSql, [ data, req.params.uuid ]).then(/* ... */).catch(/* .. */);
    ```
    
    After:
    ```js
    var insertSql = 'INSERT INTO table SET ?;';
    var updateSql = 'UPDATE table SET ? WHERE uuid = ?;';
    
    var data = {
      uuid : /** some uuid */,
      /* other properties ... */
    };
    
    // convert the hex uuid into a binary uuid
    data.uuid = db.bid(data.uuid);
    
    // insert with the new data
    db.exec(insertSql, [ data ]).then(/* ... */).catch(/* .. */);
    db.exec(updateSql, [ data, db.bid(req.params.uuid) ]).then(/* ... */).catch(/* .. */);
    ```
    
    I'd be curious if we can come up with a better API for binary
    conversions.  The currenct method is pragmatic, but possibly unclear.
    jniles committed Mar 23, 2016
    Configuration menu
    Copy the full SHA
    c9d3f5b View commit details
    Browse the repository at this point in the history