Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Structure aliases to save disk space #12

Open
namlook opened this Issue · 2 comments

1 participant

@namlook
Owner

from Christian Joudrey
We could add a dict called "structure_aliases" to Document which would serve as an alias when performing writes and reads.
For instance:

class User(Document):
    structure = {
      'u': unicode,
      'p': unicode
    }
    required_fields = [
      'u', 'p'
    ]
    structure_aliases = {
      'u': 'username',
      'p': 'password'
    }

The size of a collection can dramatically increase in size when there are many columns with long names.
Structure aliases would allow one to perform read and writes using "username" and "password" as column names, but they would really be stored as "u" and "p" in MongoDb thus saving (in theory) 14 bytes per row.

@namlook
Owner

via cjoudrey:

I think I might have made a mistake in my implementation example.
The example should read:

class User(Document):
  structure = {
    'u': unicode,
    'p': unicode
  }
  structure_aliases = {
    'u': 'username',
    'p': 'password'
  }
  required_fields = [
    'username', 'password'
  ]

The idea is that once you set an alias on a field, it is no longer known as it's original name throughout the model.

@namlook
Owner

via Christopher Grebs:

Why not using

class User(Document):
  structure = {
    'username': unicode,
    'password': unicode
  }
  structure_aliases = {
    'username': 'u',
    'password': 'p',
  }
  required_fields = [
    'username', 'password'
  ]

For the API so that the structure_alias property is only relevant for the presistence layer. This should be a bit more easy to implement.

Regards, Christopherl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.