Comments (4)
Nothing in sourced
causes a requirement to have an id
property. sourced-repo-mongo
does make special use of that property, but you could also provide some different index property. And another sourced-repo-cowbell
could do things differently.
If I were to make a dev-centric constraint, it would be in the .commit function of sourced-repo-mongo
to throw or return an error if attempting to commit an entity that does not have an id.
from sourced.
And another sourced-repo-cowbell could do things differently.
I think it would be problematic if sourced-repo-cowbell
decided it needed your entities to include a pk
field (or whatever) while sourced-repo-mongo
requires id
. It seems to me that the entity has the right to own what it's primary key is, and then a repository can just use the value for that key. If you don't do that, then it presents an interoperability problem and you have to change your entity depending on what repository you are using.
from sourced.
Just out of interest though, what do you use to handle an auto-increment sequence for id's (in the context that I'm coming from an experience where the SQL based ORM just did it for you)?
from sourced.
It's up to you to implement your id scheme. There a lots of modules that
can help do this.
You can't just let a database give you a new entity id, because that column
(or property with some sort of index on it, in a document db) is not going
to be unique. There will be many events of a single id. So autoincrement
won't work.
In general, though, if you search around you'll find lots of arguments
against using auto-incrementing ids.
If I'm creating entities that won't likely need to be sharded in any
particular way, I usually use the https://www.npmjs.com/package/uuid .v4()
method, but there are plenty more such as meteor's implementation:
https://github.com/eface2face/meteor-mongo-id.
If my data will be sharded alphabetically, numerically, by location, etc,
I'll typically create a function that generates a new unique id that
contains that information, and possibly also a portion of a uniqueId().
That way your services can load up and grab their appropriate data, for
caching purposes, etc.
On Thu, Sep 15, 2016 at 6:43 PM, Andrew Eddie [email protected]
wrote:
Just out of interest though, what do you use to handle an auto-increment
sequence for id's (in the context that I'm coming from an experience where
the SQL based ORM just did it for you)?—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#23 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAh3X36w8b3p30GsnKWo79MrzOE32mm2ks5qqcn3gaJpZM4J9h7n
.
from sourced.
Related Issues (19)
- What to do about circular references within entities? HOT 1
- replace _.cloneDeep for snapshots with more performant default HOT 3
- How events work with a Service Bus. HOT 4
- Unhandled "Channel ended" rejection in tests HOT 3
- Question - Inter-process events HOT 4
- Dependency Dashboard
- replay / emit HOT 7
- How to handle Entity meta? HOT 9
- Catch-all events HOT 7
- Best way to handle validation? HOT 2
- Typedef for Typescript HOT 1
- Race condition in constructor when extending an Entity HOT 15
- Merge of snapshot with Entity null properties fails HOT 1
- Auth example not working on Node v 8.11.2 HOT 2
- replaying HOT 1
- The automated release is failing 🚨 HOT 7
- Entity constructor arity during deserialization HOT 5
- Missing License file. HOT 1
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 sourced.