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

Add Date Time Range type #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add Date Time Range type #2

wants to merge 4 commits into from

Conversation

izavits
Copy link
Contributor

@izavits izavits commented Sep 8, 2016

No description provided.

@resin-jenkins
Copy link

Can one of the admins verify this patch?

@Page-
Copy link
Collaborator

Page- commented Sep 8, 2016

add to whitelist

nativeProperties:
has:
Begin: (from) -> ['RangeBegin', from]
End: (from) -> ['RangeEng', from]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing RangeEng should be RangeEnd?

fetchProcessing: (data, callback) ->
if data?
res =
Start: data.split(',')[0].slice(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to do this .split only once, maybe something like:

[ start, end ] = data.slice(1, -1).split(',')

@izavits
Copy link
Contributor Author

izavits commented Dec 15, 2016

Moved dataTypeGen from abstract-sql-compiler based on this comment: balena-io-modules/lf-to-abstract-sql#3 (comment)

if !err
defaultValue = value
else
defaultValue = null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the defaultValue is invalid we should actually throw an error rather than just silently ignoring it - if we've tried to use a default value it's probably required for things to work properly.

@@ -18,4 +18,14 @@
callback(err)
return
callback(null, value.toLocaleTimeString())

dataTypeGen: (engine, dataType, necessity, index = '', defaultValue) ->
if defaultValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would remove the option of having a default value of 0, false, '' etc, it should be if defaultValue? to check for nullish values directly (which is ok since a default value of null is equivalent to no default)

@@ -18,4 +18,14 @@
callback(err)
return
callback(null, value.toLocaleTimeString())

dataTypeGen: (engine, dataType, necessity, index = '', defaultValue) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see all of the default value checking in $type.dataTypeGen functions are the same, so it can be pushed directly into TypeUtils.dataTypeGen and have this bit just be dataTypeGen: TypeUtils.dataTypeGen

Copy link
Contributor Author

@izavits izavits Dec 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a default value equal to CURRENT_TIMESTAMP (e.g. in Date Time type) which will not get caught by the validate function. So these cases need a special treatment I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if I move everything to TypeUtils.dataTypeGen I won't be able to reference lets say the per type validate from there. (I assume, by looking how the types.js is being created)

if defaultValue
@validate defaultValue, true, (err, value) ->
if !err
defaultValue = value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works because our "async" callback is actually synchronous, if you try to do a default value in the Hashed datatype then it will break because that is actually truly async (and so this will happen after we've already returned the datatype, making the default value be the unprocessed one). Therefore we need to turn this into an async function that accepts a callback - if you're feeling up for it it would also be great to turn it into a dual interface api that supports both promises and callbacks by doing something like

fn = (..., callback) ->
	PromiseStuff...
	.asCallback(callback)

with http://bluebirdjs.com/docs/api/ascallback.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly should be turned into an async function? The validate function you mean?

callback('is not a date time range object: ' + value)
else
# Check with hasOwnProperty since null values are allowed
if value.hasOwnProperty('Start') and value.hasOwnProperty('End') and value.hasOwnProperty('Bounds')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces the properties into a specific case where otherwise we would allow any case (with the .toLowerCase() below). I think it does make sense to be case insensitive, so maybe after the for loop we can do an if !start? or !end? or !bounds? to check that all the properties were set

when 'end'
end = componentValue
when 'bounds'
bounds = componentValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to validate bounds here, because we access it using index properties below but if it's actually a number for instance then that will fail (and in general only certain values make sense)

when 'start'
start = componentValue
when 'end'
end = componentValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do some validation of this?

for own component, componentValue of value
switch component.toLowerCase()
when 'start'
start = componentValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do some validation of this?

@petrosagg petrosagg removed their request for review May 17, 2017 01:34
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

Successfully merging this pull request may close these issues.

3 participants