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

is it possible to insert new data in a specific row? #133

Open
jorgemejia opened this issue Feb 1, 2017 · 1 comment
Open

is it possible to insert new data in a specific row? #133

jorgemejia opened this issue Feb 1, 2017 · 1 comment

Comments

@jorgemejia
Copy link

I want to insert new data in a specific row

Something like this:

db({id:key}).get()[0].insert(newInfo)

or

db({id:key}).insert(newInfo)

@csterritt
Copy link

csterritt commented Feb 18, 2017

You can always add an 'order' field, and use it for sorting when you want data in order.

You might start with assigning 1, 2, 3, 4... and then realize that if you want to do an insert somewhere, you have to renumber everything above where you're inserting.

JavaScript numbers have enough precision, however, that you can step by something large (say, 10,000) in assigning ordering, and then just pick a number halfway between the two you want to insert between, so for example you'd insert order 25,000 between 20,000 and 30,000, and later you could insert 22,500 between 20,000 and 25,000, and so on.

Of course, you'll have to watch out for the (hopefully unusual!) case of having every integer between 'n' and 'm' assigned, and then recognize that and perhaps renumber everything. But it'd be a rare case.

Remember that JavaScript only has Number, which is a 64-bit floating point value. It's up to you if you want to go into non-integer values. Math.floor is your friend :-)

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

No branches or pull requests

2 participants