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

Using the 'format' method to ensure the ID is properly formated befor… #1338

Conversation

castarco
Copy link

Using the 'format' method to ensure the ID is properly formated before doing an update or delete query.

This commit allows using special data types as IDs. For example, we are using binary data, something similar to UUIDv4 (but not exactly the same), and we're using the format and parse methods to handle the transformations between the table representation and the internal program representation.

@vellotis
Copy link
Contributor

Hi @castarco

Some tests would be welcomed to confirm the necessity of this change.

@castarco
Copy link
Author

Hi @vellotis , ok, thank you. I'll try to add these tests.

@castarco
Copy link
Author

Hi again @vellotis . I'm facing some trouble to find the best way to test this.
I think I have to test something like:

  1. Create a simple model with an id property holding a "complex object" (nothing like a scalar: integers, strings...). The "complex" object should be simple enough to not obscure the test. I'm thinking on something like an object with two integer properties.
  2. Add the format and parse methods to this model. Using a simple bijective transformation.
  3. Create an entity and store it in the DB.
  4. Try to update it with the patch option and verify that no NoRowsUpdatedError has been thrown.
  5. Re-read from DB the object and verify that the correct ID has been retrieved?

Thank you for your time.

@vellotis
Copy link
Contributor

@castarco, for the delay

I guess that this would be enough. Are you still willing to finish the PR?

@adnanoner
Copy link

adnanoner commented Nov 4, 2016

Any update @castarco ? Also, how do you select an uuid (since they are stored as bytes)?

For those interested I'm using parse with the node-uuid package (and am using a mysql function to convert the uuid in the database as per https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/ ):

  parse: function (attrs) {
    attrs.uuid = uuid.unparse(attrs.uuid);
    return attrs;
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants