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

Database. Use '/' (or anything else) instead of '.' to navigate through the nested tree. #36

Closed
Sediug opened this issue Feb 15, 2018 · 3 comments
Assignees
Milestone

Comments

@Sediug
Copy link
Member

Sediug commented Feb 15, 2018

I think this will be in the best interest for all db users and it'll prevent errors with some nested levels that may be using dots in their keys. I said "/" to copy firebase behaviour .ref('posts/' + postId + '/starCount')

It'll be nice for 1.0.

Ex in Database.get(point) :

function get(point) {
	if(point && typeof(point) === 'string') {
		var tree = point.split('.'),
			parent = goblin.db;

		for (var i = 0; i < tree.length; i++) {
			if(i !== tree.length-1) {
				if(typeof parent[tree[i]] === 'undefined') {
					// If there is no child here, won't be deeper. Return undefined
					return undefined;
				}
				parent = parent[tree[i]];
			} else {
				return parent[tree[i]];
			}
		}
	} else {
		return goblin.db;
	}
}
@CodingCarlos
Copy link
Member

Cool. I used . because I've just wanted it to work. We could even move the nesting character to a configurable setting and set the default to / to be more friendly to firebase syntax.

@Sediug
Copy link
Member Author

Sediug commented Feb 19, 2018

Cool. Agree .

@Sediug
Copy link
Member Author

Sediug commented Feb 19, 2018

If we all agree I'd say this may be a good feature to have in https://github.com/GoblinDBRocks/GoblinDB/milestone/3

@Sediug Sediug added this to the v.0.1.0 milestone Mar 4, 2018
Sediug added a commit that referenced this issue Mar 11, 2018
@Sediug Sediug closed this as completed Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants