Comments (6)
There is no concept of order (or next) for DDB primary keys. To define an "ID" you would need both the hashkey and the (optional) range key. The range key has an order for a given hash key, and you could be interested in generating the next one, but notice that the range key itself doesn't constitute an ID. Many objects could share the same range key or hashkey but not both.
If what you are trying to do is to generate the next range key for a given hash key, I think you are out of luck. You either need to track state somehow, or make sure there is no race condition between the moment you read the last id and you write the next one. There is no way in DDB to make a write based on a condition for a different key.
I'm probably misunderstanding your question completely, sorry if that's the case.
from faraday.
Sounds like my question was confusing. In the README, you show that it is vital to manually add an :id (primary key) to the map before inserting it into the database. In the example, you simply appear to be counting up from 0. In a real application, how can you guarantee to pick a new :id value for each new map you add to the database? (For example, some databases establish the primary key as an auto-incrementing integer. Mongo automatically creates a UUID to serve as the id. It's not clear if the UUID approach would work with faraday, because the implication is that id's need to be numbers, not a long string.) So in general, what's the recommended process for guaranteeing a unique ID?
from faraday.
Oh I see. That's just a toy example. Notice that when the table is being created:
[:id :n] ; Primary key named "id", (:n => number type)
that :n is saying that the id attribute is a number, but it could also be a string or binary.
I don't think there is a "safe" way to generate these ids in a distributed system, without storing state somewhere. But also, remember that the hash keys (:id here) don't have inherent order, you can not retrieve a sorted list from DynamoDB for instance.
Long enough random strings/numbers are an option. In my view, generating the keys is definitely beyond the project goals. Speaking for myself here, don't know what is @ptaoussanis 's view on the matter.
from faraday.
Hi Mark, Sebastián's correct. (Thanks @paraseba!)
Since the primary key also acts as an index, you'll often want to provide something that's meaningful to your application like a username, product code, etc. Otherwise a simple UUID would be quite appropriate.
Note that there'd be no real benefit to having incremental primary ids since DDB automatically partitions over the primary key space and so range queries wouldn't be a possibility anyway. That's where the "range" key comes in handy, as it's designed to play well with the DDB key partitioning.
Does that help / make sense?
from faraday.
Yes, thanks.
from faraday.
BTW feel free to shout if you run into any other problems, the docs are currently serviceable at best.
from faraday.
Related Issues (20)
- Add support for the document API HOT 1
- CI integration HOT 5
- Remove support for `:expected` HOT 3
- attribute_not_exists not respected consistently HOT 3
- Support for Streams HOT 8
- missing ScanIndexForward option with far/scan HOT 1
- Request: custom keywordization routine HOT 3
- Is the scan function safe for large tables? HOT 7
- Upgrade to 1.11.16+ of aws-sdk-java for task-level IAM role support in AWS ECS HOT 9
- Add support for DynamoDB Transactions HOT 6
- Upgrade to 1.11.459 of aws-sdk-java for management of On Demand tables
- Upload all doc versions to http://taoensso.github.io/faraday/{version}
- Porting to AWS SDK v2 HOT 16
- missing page-size/max-result-size option with query HOT 1
- Support empty strings HOT 4
- not listing tables HOT 14
- Setting `region` in client-opts causes ClassCastException
- String index names cause type error HOT 3
- Local docker example from readme only with `-p 8000:8000` arg HOT 1
- Possibly confusing dependencies found HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faraday.