Comments (6)
I'm not sure I fully understand the issue but I did notice the other day an inconsistency between the date format returned from a create
and a query
. I'm happy to look into this but would you be able to provide a breaking test case or an example how you found this issue? Thanks
from dynogels.
In this particular case, I was attempting to store a date in a nested property. For example, take a look at this code using Joi:
'use strict';
const Joi = require('joi');
let schema = Joi.object().keys({
a: Joi.object().keys({
b: Joi.date()
})
});
schema.validate({ a: { b: '2016-01-01' } }, (err, data) => console.log(err || data));
This successfully converts the a.b
attribute to a JavaScript Date
object. However, if this schema is used for a table and the same object here is stored in it, the a.b
attribute is removed. Presumably either dynogels or the DynamoDB Document Client don't understand how to deal with Date
objects?
from dynogels.
I also found the inconsistency between the date format returned from create
and get
. Basically if in the schema, I use Joi.date()
, then it will be a Date
object in the response of create
, but it will be a string in the response of get
.
Using Joi.string().isoDate()
is a workaround. But I think create
should provide a more consistent behavior. One possible way is to change create
to serialize the response from dynamodb document client and return it (table.js:195), just same as what update
is doing now(table.js:368).
from dynogels.
Is this related to #107?
from dynogels.
Ok so a joi.date()
will validate successfully for a javascript Date object, a date string or a number of milliseconds. Joi Dates
DynamoDB does not have a date type, but you can store dates as strings (ISO 8601 date strings) or as numbers (epoch time). AWS Naming Rules and Data Types
I'm not sure that we want to convert all date strings to javascript Date objects when we retrieve them from the database. It seems like the developer's prerogative to determine the data types. However, Dynogels should be consistent between the different methods. If create
serializes Date objects to strings then it should report that it stored a string.
from dynogels.
I'm not sure that we want to convert all date strings to javascript Date objects when we retrieve them from the database. It seems like the developer's prerogative to determine the data types. However, Dynogels should be consistent between the different methods. If
create
serializes Date objects to strings then it should report that it stored a string.
+1 in general, though I would not be opposed to some option to transform dates. I would want it to be flexible enough that a different factory can be substituted. For example, some developers may want to use momentjs instead of the built-in Date
.
The challenge with transforming dates is detecting what values need to be transformed, especially when dealing with nested structures and Joi.alternative()
schemas, where some alternatives have dates and some don't. It seems like the only way to really be bulletproof about this is to validate the retrieved document with the schema, and let Joi transform what it will. There have been some cases in my own code where this would be useful, and it's particularly useful for backwards-compatible schema changes, where the new Joi schema can effectively migrate data on-the-fly. (For example, adding a new attribute with a default value -- old records currently just won't get that value until you save them again and this creates its own level of pain, where your application code must be able to deal with the absence of the attribute. It would be nicer for Dynogels to take care of this detail.)
So by implementing that feature, we'd effectively get this feature for free. I really like the idea that the schema coerces stored objects to match it. It would provide a much higher degree of consistency and reliability.
However, this approach can be problematic in the case where the stored data doesn't validate against the schema. It's not clear what expected behavior would be in that case.
from dynogels.
Related Issues (20)
- Does not enforce required() on nested property HOT 6
- What is the best way to convert a list of objects HOT 1
- Provide access to the AWS request object
- Model.validate not in latest release HOT 1
- Add transactions support HOT 1
- A method which returns the raw DynamoDB params for creating an item
- When I do an .updateAsync() with ReturnValues I recieve a type error
- Item.set doesn't work as advertised HOT 3
- Security question?
- while updating the model getting validationException HOT 1
- Project is dead? HOT 27
- using reserved word in schema causes silent error
- Enable On-Demand Billing Mode
- Cannot use "startKey" when using an index HOT 1
- 'updatedAt' field doesn't change once set.
- ValidationException on .destroy() method HOT 3
- Update joi dependency to use @hapi/joi HOT 6
- Keep getting Error: Invalid schema content when I use define HOT 3
- Stale library? HOT 1
- Is it possible to run dynogels with version 3 of AWS
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 dynogels.