how can I use sequelize and db-link to retrieve tables from a remote postgres database? - database

I have 2 database: one is remote the other is local, I should connect to remote database and retrieve the data from that database and copy in my database.
I can use something like db-link to connect my db to the remote db. How can I retrieve the data from remote db and sync the data from it to my local db using sequelize?
What I should do? How should I connect the 2 databases?
This is the model for the table from the remote database:
Material.init(
{
material_id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
product_code: {
type: DataTypes.STRING,
allowNull: false,
},
stock_type: {
type: DataTypes.STRING,
allowNull: false,
},
stock_name: {
type: DataTypes.STRING,
allowNull: false,
},
product_name: {
type: DataTypes.STRING,
allowNull: false,
},
metarial_quality: {
type: DataTypes.STRING,
allowNull: true,
},
explanation: {
type: DataTypes.STRING,
allowNull: true,
},
thickness: {
type: DataTypes.DECIMAL,
allowNull: true,
},
length: {
type: DataTypes.DECIMAL,
allowNull: true,
},
diameter: {
type: DataTypes.DECIMAL,
allowNull: true,
},
category: {
type: DataTypes.STRING,
allowNull: true,
},
color: {
type: DataTypes.STRING,
allowNull: true,
},
unit: {
type: DataTypes.STRING,
},
height: {
type: DataTypes.DECIMAL,
},
net_kg: {
type: DataTypes.DECIMAL,
},
gross_kg: {
type: DataTypes.DECIMAL,
},
pieces_in_box: {
type: DataTypes.INTEGER,
},
volume: {
type: DataTypes.DECIMAL,
},
},
{
sequelize,
modelName: "material",
}
);
return Material;
};
The model in my local database
{
material_id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
product_code: {
type: DataTypes.STRING,
allowNull: false,
},
stock_type: {
type: DataTypes.STRING,
allowNull: false,
},
stock_name: {
type: DataTypes.STRING,
allowNull: false,
},
product_name: {
type: DataTypes.STRING,
allowNull: false,
},
metarial_quality: {
type: DataTypes.STRING,
allowNull: true,
},
explanation: {
type: DataTypes.STRING,
allowNull: true,
},
thickness: {
type: DataTypes.DECIMAL,
allowNull: true,
},
length: {
type: DataTypes.DECIMAL,
allowNull: true,
},
diameter: {
type: DataTypes.DECIMAL,
allowNull: true,
},
category: {
type: DataTypes.STRING,
allowNull: true,
},
color: {
type: DataTypes.STRING,
allowNull: true,
},
unit: {
type: DataTypes.STRING,
},
height: {
type: DataTypes.DECIMAL,
},
net_kg: {
type: DataTypes.DECIMAL,
},
gross_kg: {
type: DataTypes.DECIMAL,
},
pieces_in_box: {
type: DataTypes.INTEGER,
},
volume: {
type: DataTypes.DECIMAL,
},
},
{
sequelize,
modelName: 'material',
tableName: 'material',
schema: 'public',
timestamps: false,
readOnly: true,
}
);

Related

Dynamic bind kendo grid dataSource binded to directive

I create dataSourec in the controller
$scope.dataSource = new kendo.data.DataSource({
transport: {
read: function (e) {
e.success(response.data.value);
}
},
serverFiltering: true,
serverSorting: true,
pageSize: 20,
schema: {
model: {
fields: {
languageId: { type: 'number', editable: true, nullable: false },
dateStart: { type: 'date', ediitable: true },
dateEnd: { type: 'date', ediitable: true },
count: { type: 'number', editable: true, nullable: false }
}
}
}
});
Then I bind it to my component
<div data-ng-if="!displayList">
<analytics-grid data-data-source="dataSource"></analytics-grid>
</div
where I add it to options of my grid
ctrl.gridOptions = {
dataSource: ctrl.dataSource,
sortable: true,
pageable: true,
columns: [{
field: "languageId",
title: "language",
width: "120px",
filterable: false,
values: _languagesLookupDS.data().toJSON()
}, {
field: "count",
title: "count"
}, {
field: "dateStart",
title: "dateStart"
}, {
field: "dateEnd",
title: "dateEnd"
}],
editable: {
mode: 'popup',
confirmation: true
},
messages: { commands: { create: "" } }
};
and then bind to kendo grid in the component view
<kendo-grid data-k-options="$ctrl.gridOptions" data-k-ng-delay="$ctrl.gridOptions" data-k-rebind="$ctrl.dataSource"></kendo-grid>
I show component view when someone switch the button(data-ng-if="!displayList" in code above). I have to switch button to displayList = true and then again to displayList = false, to update grid data, why it do not update dynamicly when dataSource change in my controller, and button is set to show kendoGrid?
I have resolved the problem by declare ctrl.gridOptions as function
ctrl.gridOptions = function () {
return {
dataSource: ctrl.dataSource,
sortable: true,
columns: [{
field: "languageId",
title: "language",
width: "120px",
filterable: false,
values: _languagesLookupDS.data().toJSON()
}, {
field: "count",
title: "count"
}, {
field: "dateStart",
title: "dateStart"
}, {
field: "dateEnd",
title: "dateEnd"
}]
};
}
and then bind it to the view
<kendo-grid data-k-scope-field="$ctrl.analyticsGrid" data-k-options="$ctrl.gridOptions()" data-k-rebind="$ctrl.dataSource"></kendo-grid>
My job mate told that problem occurred couse view was looking for object of options and don't know how to resolve it when dataSource change. Right now it just call method and get options with new dataSource.

Kendo Angular grid inline editing

I want to implement inline editing in Kendo Angular Grid. My Grid HTML is as below in an angular view
<div kendo-grid="bankRegisterGrid" k-options="bankRegisterGridOptions" ></div>
My controller code is as
$scope.bankRegisterGridOptions = {
resizable: true,
dataSource: {
batch: true,
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number", nullable: false },
ReferenceNo: { type: "string"},
AHead: { type: "string"},
Credit: { type: "number" },
Debit: { type: "number"},
ReconDescription: { type: "string"}
}
}
},
type: "json",
transport: {
read: "../Accounting/api/AccBankRegister/GetPaged",
update: {
url: "../Accounting/api/AccBankRegister/Update",
dataType: "json",
type: "Post"
},
destroy: {
url: "../Accounting/api/AccBankRegister/Update",
dataType: "json",
type: "Post"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
pageSize: 10
},
pageable: true,
columns: [{
field: "ReferenceNo",
title: "Ref. No",
type: "string",
width: "90px"
}, {
field: "AHead",
title: "Account Head",
type: "string",
width: "250px"
},
{
field: "Credit",
title: "Credit",
type: "number",
width: "90px"
},
{
field: "Debit",
title: "Debit",
type: "number",
width: "90px"
},
{
field: "Comments",
title: "ReconDescription",
type: "string",
width: "90px"
},
{ command: ["edit", "destroy"], title: " ", width: "130px" }],
editable: "inline"
};
Af first when the layout page open the url is xxx:2815/Accounting/Accounting#/ and when I click the BankRegister menu item the url is then xxx:2815/Accounting/Accounting#/BankRegister/. Now the grid open with data. When I click Edit button I see error in firebug:
'Error: Syntax error, unrecognized expression: unsupported pseudo: kendoFocusable .... jquery-1.9.0.js (line 4411, col 7)'.
In every row Edit Button click it comes. When I click cancel button in row it goes to home page and the url is xxx:2815/Accounting/Accounting#/. What is the problem?

selecting node when using treeStore ExtJS (proxy solution)

I have tree store.
var store = Ext.create('Ext.data.TreeStore', {
root: {
autoLoad:false,
expanded: false,
children: [
{
id:"0", text: "School Friends", expanded: true, children:
[
{
id:"1", text: "Mike", leaf: true, name: "Mike", email: "mike#stackoverflow.com", phone: "345-2222"
},
{
id:"select", text: "Laura", leaf: true, name: "Laura", email: "laura#stackoverflow.com", phone: "345-3333"
}
]
}
]
}
});
and Tree panel.
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody(),
listeners:{
afterrender:function(){
var record = this.getStore().getNodeById('1');
this.getSelectionModel().select(record)
}
}
});
everything works! but when I change store, using proxy request. Selection is n*ot working*
var storeTree = Ext.create('Ext.data.TreeStore', {
autoLoad:true,
expanded: true,
proxy: {
type: 'ajax',
url: 'tree.json',
},
root: {
text: 'Ext JS',
id: 'src',
expanded: true,
// children:[]
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
I use same JSON
[
{"id":4, "text":"second",},
{
id:"0", text: "School Friends", expanded: true, children:
[
{
id:"1", text: "Mike", leaf: true, name: "Mike", email: "mike#stackoverflow.com", phone: "345-2222"
},
{
id:"select", text: "Laura", leaf: true, name: "Laura", email: "laura#stackoverflow.com", phone: "345-3333"
}
]
},
]
for example one solution:
var storeTree = Ext.create('Ext.data.TreeStore', {
autoLoad:false,
expanded: false,
proxy: {
type: 'ajax',
url: 'tree2.json',
extraParams: {o: 'SELECTED'},
},
root: {
text: 'Ext JS',
id: 'src',
expanded: true,
children:[]
},
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
});
storeTree.load({
url: 'tree.json'
});
storeTree.on({
'load': function(store) {
var node = store.getNodeById("select"); // your id here
treePanel.getSelectionModel().select([node]);
treePanel.selectPath(node.getPath());
},
single: true
});

load Data from local store

I'm facing some diffculties loading specific data records frome local store into app's views.
The store looks like this:
Ext.define('xyz.store.UserDataStore', { extend: 'Ext.data.Store',
requires: [ 'xyz.model.user' ],
config: {
autoLoad: true,
autoSync: true,
model: 'xyz.model.user',
storeId: 'myStore',
proxy: { type: 'localstorage', id: 'id' } } });
The model looks like this:
Ext.define('xyz.model.user', { extend: 'Ext.data.Model',
config: { fields: [ { name: 'token', type: 'string' }, { name: 'title' }, { name: 'login' }, { name: 'facebookId' }, { name: 'firstName', type: 'string' }, { name: 'lastName', type: 'string' }, { name: 'nationality', type: 'string' }, { name: 'birthDay', type: 'string' }, { name: 'phone' }, { name: 'mobile' }, { name: 'street' }, { name: 'city', type: 'string' }, { name: 'zipCode', type: 'int' }, { name: 'willingToTravel' }, { name: 'pictureUrl' }, { name: 'eMail' }, { name: 'publicList' } ] } });
Thank you in advance,
Sabine

Store not loaded in sencha touch

I am usning below code to store the data from the ajax request but it is not lading data on the store so Please let me know what I am doing wrong.
Here is my store class:
Ext.define("Por.store.Notes", {
extend: "Ext.data.Store",
config: {
storeId: 'Notes',
model: "Por.model.Note",
}
});
This is my model class:
Ext.define("Por.model.Note", {
extend: "Ext.data.Model",
config: {
idProperty: 'id',
fields: [
{ name: 'id', type: 'string' },
{ name: 'content_name', type: 'string' },
{ name: 'kind', type: 'string' },
{ name: 'company_name', type: 'string' },
{ name: 'note', type: 'string' },
{ name: 'attext', type: 'string' },
{ name: 'cid', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'file_extension', type: 'string' },
{ name: 'mime_image', type: 'string' },
{ name: 'ciid', type: 'string' },
{ name: 'citem_name', type: 'string' },
{ name: 'attach', type: 'string' },
{ name: 'cryptic', type: 'string' },
{ name: 'url', type: 'string' },
{ name: 'is_socialsites_share_ok', type: 'string' },
{ name: 'skey', type: 'string' },
{ name: 'lookup_id', type: 'string' },
{ name: 'lookup_kind_name', type: 'string' },
{ name: 'rid', type: 'string' },
{ name: 'content', type: 'string' },
{ name: 'clip_wm', type: 'string' },
{ name: 'vid_wm', type: 'string' },
{ name: 'flash_clip', type: 'string' },
{ name: 'module_num', type: 'string' },
{ name: 'itemtype', type: 'string' }
],
}
});
This is ajax request which I am firing :
Ext.Ajax.request({
url: url,
scope: this,
callback: callbackFn
success: function(response) {
var responseData = Ext.JSON.decode(response.responseText);
var store = Ext.getStore('Notes');
store.setData(responseData);
store.sync();
},
failure:function(response){
alert(response.status);
}
});
This is my view:
Ext.define("Por.view.NotesListContainer", {
extend: "Ext.Container",
alias: "widget.noteslistcontainer",
initialize: function () {
this.callParent(arguments);
var notesTitle = {
xtype: 'panel',
html:'<div style = " text-align:center; padding-top:10px;" >First Data</div>'
};
var notesData = {
xtype: 'panel',
html:'<div style = " padding-left:15px;">Personalized Content for ARP</div>'
};
This is my list view:
var notesList = {
xtype: "noteslist",
store: Ext.getStore("Notes"),
listeners: {
itemtap: { fn: this.onNotesListDisclose, scope: this }
}
};
this.add([notesTitle,notesData, notesList]);
},
onNewButtonTap: function () {
console.log("newNoteCommand");
this.fireEvent("newNoteCommand", this);
},
onNotesListDisclose: function(dv, index, item, record) {
console.log("editNoteCommand");
this.fireEvent('editNoteCommand', this, record);
},
config: {
layout: {
type: 'vbox'
}
}
});
Ext.define("Por.view.NotesList", {
extend: "Ext.dataview.List",
alias: "widget.noteslist",
config: {
loadingText: "Loading Notes...",
emptyText: "<div class=\"notes-list-empty-text\">No notes found.</div>",
onItemTap: true,
itemTpl:'<div ><div style="font-size:14px;color: #5090D0;font-weight:bold;">{content_name}</div><div style =
"clear:both;"></div></div><div><p style="font-size:12px;"> <span style="font-weight:bold;font-size:14px;"><b>Type: </b></span> {company_name}
</p></div><div><p style="font-size:12px;"><span style="font-weight:bold;font-size:14px;border:1px solid red;">Account: </span>
{lookup_kind_name} </p></div></div>'
}
});
Here is the json data:
{
"data": [{
"id": "56636",
"content_name": "Ray Zor interview",
"kind": "0",
"company_name": "The Gillette Company",
"note": "<b>Business Problem<\/b> d\r\n* Inadequate collaboration infrastructure\r\n* 100% year over year growth\r\n* Lost sales due to service issues \r\n\r\n<b>Solution<\/b>\r\n* Apollo suite v7 with Oracle add-in\r\n* AppAccelerator for SQL\r\n* Solution Consulting engagement\r\n\r\n<b>Results<\/b>\r\n* 30% in time to market process\r\n* 25% improvement in customer sat scores\r\n* Better utilization of existing IT staff",
"attext": null,
"cid": null,
"category": "Listen",
"file_extension": "rref",
"mime_image": null,
"ciid": null,
"citem_name": null,
"attach": null,
"cryptic": "48737f98c5172",
"url": null,
"is_socialsites_share_ok": null,
"skey": null,
"lookup_id": "-1",
"lookup_kind_name": "Recorded Audio Reference",
"rid": "56636",
"content": "a wma is loaded to this topic",
"clip_wm": "48738147342c1.wma",
"vid_wm": "",
"flash_clip": "",
"module_num": 0,
"itemtype": "listen"
}]
}
Either put autoLoad: true in the store
OR
store.load({
callback: function(records, operation, success) {
// the operation object contains all of the details of the load operation
console.log(records);
},
scope: this
});
You have not defined proxy and reader for Por.store.Notes. Define these configurations like -
Ext.define("Por.store.Notes", {
extend: "Ext.data.Store",
config: {
storeId: 'Notes',
model: "Por.model.Note",
proxy: {
type: "ajax",
url : url,
reader: {
type: "json",
rootProperty: "data"
}
}
}
});

Resources