Officially prefer int for IDs.
For a while I was attracted to string IDs because of the notion that "if you're not going to perform arithmetic, it shouldn't be an int". But ints make way better use of the allotted bits and I'm loving getrandbits for urandom ID generation.
This commit is contained in:
parent
cbef38ba7f
commit
720a2bebcf
1 changed files with 6 additions and 5 deletions
|
@ -132,11 +132,12 @@ class Database(metaclass=abc.ABCMeta):
|
||||||
self._worms_transaction_lock = threading.Lock()
|
self._worms_transaction_lock = threading.Lock()
|
||||||
self._worms_transaction_owner = None
|
self._worms_transaction_owner = None
|
||||||
self.transaction = TransactionContextManager(database=self)
|
self.transaction = TransactionContextManager(database=self)
|
||||||
# If your IDs are integers, you could change this to int. This way, when
|
# Since user input usually comes in the form of strings -- from command
|
||||||
# taking user input as strings, they will automatically be converted to
|
# line, http requests -- and the IDs are usually ints in the database,
|
||||||
# int when querying and caching, and you don't have to do the conversion
|
# we'll do the data conversion before making queries or responses,
|
||||||
# on the application side.
|
# so you don't have to do it in your application.
|
||||||
self.id_type = str
|
# But if your application uses string IDs, set self.id_type = str
|
||||||
|
self.id_type = int
|
||||||
self.last_commit_id = None
|
self.last_commit_id = None
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
|
Loading…
Reference in a new issue