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

Array of Objects as type #55

Closed
bozzmob opened this issue Jan 7, 2017 · 5 comments
Closed

Array of Objects as type #55

bozzmob opened this issue Jan 7, 2017 · 5 comments

Comments

@bozzmob
Copy link

bozzmob commented Jan 7, 2017

Thanks for dynogels. It's simply amazing. Impressed with the kind of coverage that it gives.

Is there a way to define JSON data type? or should we use string() type instead?
This is my scenario-

I need to build a DB with schema(rather example) that looks something like-

	"email":"sat@gmail.com" - Hash Key
        "timestamp" : ----- Range Key
	"name":"Sat"
	"phone":"9383883223"
	"version":"version"
	"additionalSigninData":{
		"key1":"value1",
		"key2":"value2"
	}

	"markedLocations":[
		{
			"latitude":"77.33",
			"longitude":"12.33",
			"name":"Home",
			"description":"my new home",
			"placeid":"55334433",
			"image":"url/abc.png"
		}
	]
  1. So, I basically need to know how do I hold values in the 'MarkedLocations' array? The array has to hold objects in it.

  2. Updating the object's attributes(say updating latitude,longitude) and adding more objects to the array has to be possible.

Please can you suggest how do I achieve this?

@bozzmob bozzmob changed the title JSON data type Array of Objects as type Jan 7, 2017
@fxpiteam
Copy link

fxpiteam commented Jan 7, 2017

+1 I have similar problem. How do we solve this? @clarkie any suggestions?

@cdhowie
Copy link
Collaborator

cdhowie commented Feb 12, 2017

The way to do this with Joi would be something like

Joi.object().keys({
    // other stuff
    markedLocations: Joi.array().items(
        Joi.object().keys({
            latitude: Joi.string(),
            longitude: Joi.string(),
            // etc
        })
    )
})

Note that DynamoDB does not store empty arrays or empty objects, so if you try to store markedLocations: [] and then fetch the same record, the attribute will be undefined and not an empty array.

@cdelgadob
Copy link

And what if these markedLocations where in a different table?
Is there a way to tell dynogels that is expecting an object but to store only one of the attributes (i.e. the object's key)?

@cdhowie
Copy link
Collaborator

cdhowie commented May 30, 2017

No. Dynogels is not an object-relational mapper.

@clarkie
Copy link
Owner

clarkie commented Jun 9, 2017

Agreed

@clarkie clarkie closed this as completed Jun 9, 2017
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

5 participants