Prisma 2: Setting Minimum & Maximum Length of a String type - prisma

I am creating a model using Prisma 2 and want to set a minimum and maximum length for one of the fields. I.e., something like this:
model Post {
...
title String #min(3) #max(240)
...
}
I just made up the above syntax. I am wondering if something like that exists in Prisma and, if so, how to do it.
Any ideas?
Thanks.

Annotation #db.VarChar
You can set the maximum length using the annotation #db.VarChar:
model Post {
...
title String #db.VarChar(240)
...
}
There is no support for adding the minimum length as for now.

Related

Maximum number of tags allowed in OpenTsdb

What is the maximum number of tags allowed in openTsdb? I read some of the documents and it seems that the default value is 8. But I am confused that whether the maximum number is 8 or is it configurable to a higher value.
I know lesser number of tags should be kept, but its the requirement.
So can I have more number of tags than 8?
It is now configurable, at least it is in version 2.3.1.
A snippet from Const.java:
static void setMaxNumTags(final short tags) {
if (tags < 1) {
throw new IllegalArgumentException("tsd.storage.max_tags must be greater than 0");
}
MAX_NUM_TAGS = tags;
}
And then a snippet from TSDB.java:
public TSDB(final HBaseClient client, final Config config) {
...
if (config.hasProperty("tsd.storage.max_tags")) {
Const.setMaxNumTags(config.getShort("tsd.storage.max_tags"));
}
...
}
Just setting the "tsd.storage.max_tags" value in opentsdb.conf and a restart is enough.
The file can be found at /usr/share/opentsdb/etc/opentsdb/ in my case.
Don't use too many tags, keep it to a fairly small number, usually up to 4 or 5 tags (By default, OpenTSDB supports a maximum of 8 tags).
OpenTSDB does not support more than 8 tags. and it is not configurable.
Not configurable but still easy to reach. You can change the source code src/core/Const.java change MAX_NUM_TAGS to some number you want.
https://github.com/StumbleUponArchive/opentsdb/blob/e68948bc/src/core/Const.java#L22
But if you really need a lot of tags you should try some other products like elasticsearch.

Parse setting explicit type using REST

I know you can set a Date field explicitly like so:
"date_brewed":{
"__type":"Date",
"iso":"2009-10-15T00:00:00.000Z"
}
But is there anyway to explicitly set the column type of 'Number' using REST? For instance, I'd like to set the column 'batch_size' to a Number instead of a string but when POST'ing via rest it keeps getting created as a string type column.
Meh, this was more of a Perl issue than a Parse issue.
What I had to do to tell Perl to treat the number like an actual number was to add a zero to the value. :/

Sailsjs/waterline specify number of decimal places in model

How do I tell my sails model that I want some specific number decimal places for a type: 'float' attribute? Like decimalPlaces: 4 or something of that ilk?
The problem is that when i post a value to this entry, the value on disk is truncated to the .00 (hundreds) place. Say I want: 3243.2352362 to be stored just as it is. Currently this is transformed into 3243.24
If it matters I'm using the sails-mysql adapter.
types: {
decimal2: function(number){
return ((number *100)%1 === 0);
}
},
attributes: {
myNumber: {
type: 'float',
decimal2: true
}
}
This is for 2 decimal places though. I cant find a way to make it for dynamically changing N as there is afaik no way to pass a parameter to custom validation.
Workaround for this issue would be to check for custom amount of decimal places in beforeValidation() function.
I would not recommend (and I don't think its possible for float, maybe) adding a constraint in the model.
I'd suggest that you set:
migrate: "safe"
in your model and set the appropriate datatype/decimal Places in your tables.

Maximum Size of characters in Page Name in CQ5

when we are creating a page using Scaffolding it is only taking page name maximum 20 characters,is there any other way to override that validation? Thanks in advance....
In the default scaffolding, (/libs/wcm/scaffolding/components/scaffolding/body.jsp) on line 242 you see the following code:
var title = frm.findField("./jcr:content/jcr:title");
if (title) {
var hint = title.getValue();
if (hint) {
params[":nameHint"] = hint;
}
}
The main thing to take away from this code is params[":nameHint"]. This param is submitted when you create a page. The nameHint paramater is what causes the node name to be limited to x amount of characters. When nameHint is submitted, it runs through a filter which formats the name for JCR. This is done to ensure a valid JCR name. It is for your protection. You can read more about this in the Algorithm for Node Name Creation section on this page: http://sling.apache.org/site/manipulating-content-the-slingpostservlet-servletspost.html
To overwrite this problem, you would need to change params[":nameHint"] to params[":name"]. Just remember, that this won't ensure a valid JCR name. If this is a concern, you can always right some code to change the title to a valid JCR name and then set it to the :name param.
One other thing, I did read this - "when :nameHint is filtered it cuts the name to a configurable maximum length (default is 20 characters)". I cannot find how this is configured though.
Configure CQ POST servlet.. and you should be good

Get statuscode text in C#

I'm using a plugin and want to perform an action based on the records statuscode value. I've seen online that you can use entity.FormattedValues["statuscode"] to get values from option sets but when try it I get an error saying "The given key was not present in the dictionary".
I know this can happen when the plugin cant find the change for the field you're looking for, but i've already checked that this does exist using entity.Contains("statuscode") and it passes by that fine but still hits this error.
Can anyone help me figure out why its failing?
Thanks
I've not seen the entity.FormattedValues before.
I usually use the entity.Attributes, e.g. entity.Attributes["statuscode"].
MSDN
Edit
Crm wraps many of the values in objects which hold additional information, in this case statuscode uses the OptionSetValue, so to get the value you need to:
((OptionSetValue)entity.Attributes["statuscode"]).Value
This will return a number, as this is the underlying value in Crm.
If you open up the customisation options in Crm, you will usually (some system fields are locked down) be able to see the label and value for each option.
If you need the label, you could either do some hardcoding based on the information in Crm.
Or you could retrieve it from the metadata services as described here.
To avoid your error, you need to check the collection you wish to use (rather than the Attributes collection):
if (entity.FormattedValues.Contains("statuscode")){
var myStatusCode = entity.FormattedValues["statuscode"];
}
However although the SDK fails to confirm this, I suspect that FormattedValues are only ever present for numeric or currency attributes. (Part-speculation on my part though).
entity.FormattedValues work only for string display value.
For example you have an optionset with display names as 1, 2, 3,
The above statement do not recognize these values because those are integers. If You have seen the exact defintion of formatted values in the below link
http://msdn.microsoft.com/en-in/library/microsoft.xrm.sdk.formattedvaluecollection.aspx
you will find this statement is valid for only string display values. If you try to use this statement with Integer values it will throw key not found in dictionary exception.
So try to avoid this statement for retrieving integer display name optionset in your code.
Try this
string Title = (bool)entity.Attributes.Contains("title") ? entity.FormattedValues["title"].ToString() : "";
When you are talking about Option set, you have value and label. What this will give you is the label. '?' will make sure that the null value is never passed.