schemaName not working for sails-postgresql - sails.js

I'm using sails v1.2.2 with sails-postgresql adapter.
Looking for using Model with specific schemaName.
But relation with mapped with default schemaName (public)
{
tableName : "t_role",
meta: {
schemaName: 'autorisation'
}
}
AdapterError: Unexpected error from database adapter: relation "public.t_role" does not exist

Hi there i'm facing the same issue when i try to upgrade to sails v1.x.x. I Try To figure it out all day long do some debug *thx for VSCode.
ps: i dont know if this approach really solve the problem, but it works
i have to add some code in two files of waterline library here are some files
forge-stage-three-query.js
i dont know how exactly the waterline works but sails will add/replace(if existing) meta attributes if u want to fetch data when you query the model add some fetch in meta properties
So Ihave to add some code like this in line 82
s3Q.using = model.tableName;
if (typeof model.meta.schemaName !== 'undefined'){
//meta property only set if query fetch : true
if (typeof s3Q.meta !== 'undefined'){
//we have to initialize propery of meta
s3Q.meta.schemaName = model.meta.schemaName;
}else{
s3Q.meta = model.meta;
}
}
And everythings works perfectly until i try to get some data with populate, and sails get crash the schema is set to public again, after i'm doing some debug again i found this file
help-find.js
in this file i need to replace some code
at line 247 replace to this code
meta: junctionTableModel.meta,
at line 290 and 441 replace to this code
var meta = childTableModel.meta;
Hope this helps..

Related

Fetching json from Mongo with Meteor

I am trying to fetch a json object from the mongodb using meteor, but I have no clue why I’m unable to do so.
I need it to be a JSON object only.
One of the entries of the collection looks like this:
[Image taken from Meteor Dev Tools]
Link: https://i.stack.imgur.com/BxRmS.png
I’m trying to fetch the value part by passing the name.
Code on front end:
export default withTracker(() => {
let aSub = Meteor.subscribe(‘allEntries’);
return {
aBoundaries: DataCollection.find({}).fetch()
}
})(Component Name);
The Meteor Call Statement on front-end:
dataFromDb = Meteor.call(‘functionToBeCalled’, ‘Sydney’);
Server-side Code:
Meteor.publish(‘allEntries’, function(){
return DataCollection.find();
});
Meteor.methods({
functionToBeCalled(aName){
return DataCollection.find({name: aName});
}
});
Another of my questions is:
Is there any way that we publish only all the names in the beginning and then publish the values on demand?
Thanks for your help in advance!
I have tried this as well, but it did not work:
functionToBeCalled(aName){
var query = {};
query['name'] = aName;
return DataCollection.find(query).fetch();
}
The issue seems to be with query.
Collection.find() returns data with cursor.
To get an array of objects, use Collection.find().fetch(). The jsons are returned as collection of array like [{json1}, {json2}].
If there is a single document, you can access the json using Collection.find().fetch()[0]. Another alternative is to use findOne. Example - Collection.findOne(). This will return a single JSON object.
use Meteor.subscribe('allEntries'), do not assign it to a variable.
Meteor.subscribe is asynchronous, it's best you ensure that your subscriptions are ready before you fetch data.
Log DataCollection.find({}).fetch() to your console
Check this official reference https://docs.meteor.com/api/pubsub.html#Meteor-subscribe.
Your second question isn't that clear.
Just in case anyone comes here to look for the answer ~~~
So... I was able to make it work with this code on the server:
Meteor.methods({
functionToBeCalled(aName){
console.log(aName);
return DataCollection.findOne({name: aName});
}
});
And this on the client:
Meteor.call('functionToBeCalled', nameToBePassed, (error,response) => {
console.log(error, "error");
console.log(response, "response"); //response here
})
Thanks for the help!

Get undefined variable trying to update the path to an uploaded file within MongoDB using angular-file-upload and MEAN.js

If someone could help me I would be eternally grateful. I have been slamming my head against a brick wall for weeks trying to get images to upload the way it is demonstrated out of the box with the MEAN.js users module. In the generated users module the file is uploaded into a directory and the path to that file is stored in a field in the mongodb document. I can get the file to upload to where it needs to go using multer and the fileupload function. However, I cannot save the path to the field within the document. I cannot figure out how to avoid getting an 'undefined' variable. I've tried creating a $window service and passing data to it as a global variable and a bunch of other things and I'm totally stuck.
I have commented the code below to demonstrate what is going awry in my server controller changeShoePicture function.
// This is the boilerplate code from the mean.js "users" module.
// I can not create a $window service or global variable to store the
// shoe data below so that I can update the shoe.shoeImageURL field
// in MongoDB with path to the successfully uploaded file.
exports.changeShoePicture = function (req, res) {
var message = null;
var shoe = req.shoe;
var upload = multer(config.uploads.shoeUpload).single('newProfilePicture');
var profileUploadFileFilter = require(path.resolve('./config/lib/multer')).profileUploadFileFilter;
console.log('i am here', shoe); // shoe is defined here.
// Filtering to upload only images. This works and proceeds to the else condition!
upload.fileFilter = profileUploadFileFilter;
upload(req, res, function (uploadError) {
if(uploadError) {
return res.status(400).send({
message: 'Error occurred while uploading profile picture'
});
} else {
//shoe image file is successfully uploaded to the location on the server,
// However the following fails because the shoe variable is undefined.
shoe.shoeImageURL = config.uploads.shoeUpload.dest + req.file.filename;
}
});
To make sure I've got this right:
The upload function is being called on your parameters passed by your route, req and res. You set the shoe var from req.shoe.
What are the chances that upload() is messing with your req?
Drop a console.log(req) in right after you call upload and report back

Deleted/Modified/Added records from extjs store

Im having the below store and modal for a grid in extjs 4.2.
Ext.define('myapp.store.myStore',{
extends:'Ext.data.Store',
modal:'myapp.modal.myModal',
storeId:'myGridStore',
data:[],//used this only when trying inline data
proxy: {
type:'memory',
reader:{
type:'json',
}
}
});
Ext.define('myapp.modal.myModal',{
extends:'Ext.data.Modal',
fields:['bla','blha']
});
The mapping to the grid,store and modal looks fine and data is populated properly loaded in the grid.
The problem is when there are modifications to the store like
grid.getStore().removeAt(rowIndex)
or
grid.getStore().add(record)
im not able to get those through the
getRemovedRecords()
and
getNewRecords()
when i load the data into the store with the
grid.getStore().loadData(ajaxCallResponse).
It works fine when i give the data inline.
Pls help me understand what im doing wrong...
if(record.phantom != true){
record.phantom = true;
}
store.loadData(record);
Check that phantom is true first then loadData, and try to use store.getNewRecords(), if phantom is true only the records will be there in getNewRecords().
try store.getModifiedRecords() instead. This will get you the new and edited records. To check if its a new record just check the records "phantom" property which will equal true.
also, if getNewRecords() and getRemovedRecords() arent returning any records, try store.sync() after a record has been added/deleted.
When adding a new record to the store I had to set the phantom attribute to true (as suggested by #Naren Sathya in a previous answer) in order for the getModifiedRecords() method to actually list those newly added records:
// Create a new default record
var newServerConfig = new App.model.mConfigServer({
id: idForNewRecord,
server: 'server',
port: 8443,
username: 'user',
password: ''
});
/* Setting the phantom property to 'true' will ensure this record will be listed
* when trying to retrieve those new records with store.getModifiedRecords() later on
*/
newServerConfig.phantom = true;
// Add it to the store
storeServers.add(newServerConfig);

How create channel to read a BLOB and write file system file

I am trying to create a image by fetching blob from MySQL DB ...
Here goes the code....
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/dbname','username','');
var query_code = "Select blob from tblname where id =59"; //
var result = dbConn.executeCachedQuery(query_code);
dbConn.close();
if (result.next())
{
var image=FileUtil.encode(result.getBytes(1));
$gc('image1', image);
}
Could anyone help me out to achieve this...
Did You receive any error with this code if so post it.
Im not sure with Mirth connect tool But as far as I know, Retrieving the BLOB image from the DB directly with any IDE/Tools is always possible but difficult with 2 ways
By encoding to BASE-64 charcter
By specifying the entire location saving it locally.
And try removing the dbconn.close(); do not use it or use it after if() statement. Because it will throw an error like "no statements were executed after dbconn.close();

Mongoose won't remove embedded documents

I'm scratching my head here, as usual it seems with node projects, and I'm not sure if I'm doing something wrong or if I've run into a bug.
I've got a schema of Server that can have any number of embedded docs called services. I'm running into a problem though where, even though I've successfully removed the individual service from the server object, when I tell it to save it doesn't remove it from the database. The save function is working because it's saving any changes I've made and is also pushing in new embedded docs, it's just not removing one that are already there.
Here is a relatively simplified example of my code:
app.put('/server/:id', function(req, res, next){
app.Server.findOne({_id: req.params.id}, function(err, server) {
server.updated = new Date();
...
for (var num = _.size(req.body.server.services) - 1; num >= 0; num--){
// Is this a new service or an existing one
if (server.services[num]) {
// Is it marked for deletion? If so, delete it
if (req.body.server.services[num].delete == "true") {
server.services[num].remove()
} else { // else, update it
server.services[num].type = req.body.server.services[num].type
...
}
} else {
// It's new, add it
delete req.body.server.services[num]["delete"]
server.services.push(req.body.server.services[num]);
}
}
server.save(function(err){
if (!err) {
req.flash('success', 'Server updated')
} else {
req.flash('error', 'Err, Something broke when we tried to save your server. Sorry!')
console.log(err)
}
res.redirect('/')
});
})
});
So the remove() is actually removing the service. If I do a server.toObject() before the save, it's not there. Any ideas why it wouldn't be removing it from the database when it saves?
Edit: I suppose the version numbers would be helpful. node#0.4.2, mongoose#1.1.5 express#2.0.0rc
I could be wrong, since I've not tested your example, but this sounds like Mongoose isn't detecting that the embedded document is modified.
From the schema types documentation page:
Since it is a schema-less type, you can change the value to anything else you like, but Mongoose loses the ability to auto detect/save those changes. To "tell" Mongoose that the value of a Mixed type has changed, call the .markModified(path) method of the document passing the path to the Mixed type you just changed.
person.anything = { x: [3, 4, { y: "changed" }] };
person.markModified('anything');
person.save(); // anything will now get saved
So you answer might be as simple as using the markModified() function.
I found a way to temporary fix this problem.
What I did is load the embedded documents into an array, splice the one to be deleted and replace the array. Something like this:
var oldusers = dl.users;
oldusers.splice(dl.users.indexOf(req.currentUser.id), 1);
dl.users = oldusers;
dl.save(function(err) {...
I know that depending on the size of the document it will