I am managing offline db using jaydata + sqlite.
In jaydata nvarchar(20) is not a valid datatype so I need to use 'String' as datatype.
Online db is using datatype as nvarchar(20).
Now,my question is:
Is it possible to map both offline db and online db because 'nvarchar(20)' is datatype on online db and 'string' is datatype on offline db' ??
This is what I am supposed to create in my online db:
This is what I have created in my offline db with jaydata+sqlite:
// Table definition of user
$data.Entity.extend("user", {
'UserId' : { key:true,type:'int',nullable:false,required:true },
'Username' : { type:'string',nullable:false,required:true },
'Password' : { type:'string',nullable:false,required:true},
'UserType' : { type:'string',nullable:false,required:true},
'CreatorId' : { type:'int',nullable:false,required:true},
'CreatedAt' : { type:'datetime',nullable:true},
'ModifierId' : { type:'int',nullable:true},
'ModidiedAt' : { type:'datetime',nullable:true},
'IsDeleted' : { type:'boolean',nullable:false,required:true}
});
disclaimer: I am one of the creators of JayData
You can use your online schema to create an offline database. NVarchar(20) is not even an OData type - so I guess it will just be 'Edm.String' with a maxLength=20 modifier. Edm.String is however mapped to the type "String" in JavaScript.
Sharing your schema definition would also help me giving better answers.
EDITED
The following schema definition would work with an online endpoint (provided with odata or REST) and would also create the same table definition locally.
$data.Entity.extend("user", {
'userid' : { key:true,type:'string', maxLength:216,required:true },
'username' : { type:'string',maxLength:216, required:true },
'password' : { type:'string',maxLength:64,required:true},
....
});
Is this what you needed? Please note that in JS every string is nvarchar since javascript is UTF8 internally.
Related
How to set Firebase rules to allow only listed userid in a db (or a key or node or subset of a db) to r/w in another key/subset of the same database?
This link only mentioned of w/r of the same node/key/subset of a db.
What I want to set is for example the following db :
'SomeDB' : {
'ListOfUsers': {
'key1' : { 'key': 'key1', 'name' : 'name1' },
'key2' : { 'key' : 'key2', 'name':'name2'},
and so on...
},
{'SomethingForWR': 'Some Database'}
The rules should be read and write is only allowed for 'SomethingForWR' (which is part of 'SomeDB') if the 'auth.uid' is equal to one or one of the keys in 'ListOfUsers' (which is also part of 'SomeDB')
If you want to check if a key exists in ListOfUsers you can do so with:
root.child('ListOfUsers').child('keyYouWantToCheck').exists()
With that knowledge, your rule to allow a user access to SomethingForWR if their UID exists in ListOfUsers could be something like this:
{
"rules": {
...
"SomethingForWR": {
".read": "root.child('ListOfUsers').child(auth.uid).exists()"
}
}
}
Edit for clarity: There are no error messages, it simply returns an empty list if the input string is from the context.arguments, suggesting that it simply isn't getting the input variable out on the query tester (setting it up incorrectly brings up that famous typing error of course). I've also made this into a pipeline with the exact same result. Looking around, people suggest making an intermediate object, but surely I'm just getting my input variables out wrong somehow.
I'm working on a project in AWS Appsync using DynamoDB and I've run into a problem with the context.arguments input.
Basically the code all works if I hardcode the string for the book id into the query (full context to follow), but if I use the context.arguments, it simply refuses to work properly, returning an empty array for the "spines".
I have the following types in my schema:
type Book {
id: ID!
title: String
spines: [Spine]
}
type Spine {
id: ID!
name: String
bookId: ID!
}
I use the following query:
type Query {
getBook(id: ID!): Book
query getBook($bookId: ID!){
getBook(id: $bookId){
title
id
spines {
name
bookId
}
}
}
With the following input (assume this is a relevant guid):
{
"bookId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
}
And this resolver for the spines object:
{
"version" : "2017-02-28",
"operation" : "Query",
"index" : "bookId-index",
"query" : {
"expression": "#bookId = :bookId",
"expressionNames" : {
"#bookId" : "bookId"
},
"expressionValues" : {
":bookId" : { "S" : "${context.arguments.id}" }
}
}
}
}
I made sure my data set contained false positives too (spines for other books) so that I know when my query brings back the correct data.
This works if I hardcode a guid as string instead of using context.arguments, and gets exactly what I'm looking for for each book guid.
For example, replacing the expression values with this works perfectly:
"expressionValues" : {
":bookId" : { "S" : "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" }
}
Why does "${context.arguments.id}" not get the input variable here the same way as it seems to in other queries?
Thanks to #IonutTrestian for pointing me in the right direction.
$ctx.args was empty, but I decided to go up the chain to see what was in the entire context, so $util.error($util.toJson($ctx)).
The json object I found included a little object called "Source", which contained the query return for the Book object.
Long story short, $ctx.source.id when applied to my query worked a charm.
I also know a bit more about debugging DynamoDB resolvers in case I encounter problems like this in future. Thank you so much!
I am asking myself if this kind of database structure is good, because of identifying the user with an PK AND putting the UID again under that PK. I dont know if that makes really sence or even more, could be dangerous?
{
"Users" : {
"7idb6ThWR8aqmnEHFao5GRCV1kI3" : {
"dPicture" : "https://firebasestorage.googleapis.com/v0/b/parkir-ngasal.appspot.com/o/Profile_images%2Fcropped1465266876.jpg?alt=media&token=44f83fdf-935a-4b3c-8138-561dcba2fca7",
"status" : "hi my name is erik",
"uid" : "7idb6ThWR8aqmnEHFao5GRCV1kI3",
"username" : "erik"
}
},
"posts" : {
"-KfsrGsY8TWb2wiMFtAq" : {
"dPicture" : "https://firebasestorage.googleapis.com/v0/b/parkir-ngasal.appspot.com/o/Profile_images%2Fcropped1465266876.jpg?alt=media&token=44f83fdf-935a-4b3c-8138-561dcba2fca7",
"image" : "https://firebasestorage.googleapis.com/v0/b/parkir-ngasal.appspot.com/o/Post_Images%2Fcropped1354055061.jpg?alt=media&token=77fbc9ed-4356-43c1-b7bb-9563300a8b7b",
"small_title" : "tes",
"summary" : "tes",
"title" : "tes",
"uid" : "7idb6ThWR8aqmnEHFao5GRCV1kI3",
"username" : "erik"
}
}
}
It's not dangerous. The security you set at the parent level traverses downward. From the Firebase docs:
.read and .write rules work from top-down, with shallower rules
overriding deeper rules. If a rule grants read or write permissions at
a particular path, then it also grants access to all child nodes under
it.
As to if it makes sense...that's up to you decide. While there's nothing wrong with duplicating the key inside the data structure, it's not needed. It's just as easy to retrieve the data from the key as it is from the payload.
const data = await firebase.database().ref(`/Users/`).once('value');
const users = _.map(data.val(), (val, key) => {
return {
userId: key,
val.username,
val.dPicture,
val.status
};
});
I am using Kaa 0.10.0 and I have defined Log schema and created a MongoDB log appender.
My question is when I upload a log record by client and save it to MongoDB by log appender, the optional field (driverLicenseNo, e.g.) json format would be like as below.
{
"event" : {
"driverLicenseNo" : {
"string" : "310103198702092345"
}
}
}
or if value is null,
{
"event" : {
"driverLicenseNo" : null
}
}
My expectation is
{
"event" : {
"driverLicenseNo" : "310103198702092345"
}
}
or if value is null
{
"event" : {
"driverLicenseNo" : null
}
}
Is there any configuration can be set to get the MongoDB json format as expected?
Thanks!
Xiangfeng Qi
The optional field attribute (boolean, false by default) determines whether or not the field in the record is optional.
Internally, Kaa translates optional fields into union fields with the null type at the top of the list. For more information,
see Automatic generation of records. If there is an optional union field, Kaa automatically puts null at the top of the types list in the union definition.
You can find this description in documentation.
I am trying to do an upsert on the server side with a custom field as the unique identifier instead of a mongo id (data is being pulled from a 3rd party api).
A simplified version of what I am trying to achieve:
var myItem = {
myUniqueID : 'abc123',
name: 'foo'
};
MyCollection.upsert(
{
"myUniqueID ": myItem.myUniqueID
},
{
"$set": myItem
}
);
I receive the following error:
Error: Meteor does not currently support objects other than ObjectID as ids
It appears that this was caused by me adding:
MyCollection._ensureIndex({myUniqueID : 1}, {unique: 1});
right after declaring the Mongo Collection... even when I commented this line out the damage had been done.. I had to rename the collection (essentially create a new collection) to get past it.