[AdSense-A]
[AdSense-B]
[AdSense-A]
[AdSense-B]
In this video tutorial we explain how web servers works, what is multi threaded architecture and limitations of multi threaded web server architecture
[AdSense-A]
[AdSense-B]
Getting this Error for find query using sequelize library in nodejs:
Error: SequelizeDatabaseError: operator does not exist: character varying = bigint1
[AdSense-A]
const sequelizeHelper = require("../helpers/sequelizeHelper");
const db = sequelizeHelper.db;
const sqlOperator = sequelizeHelper.sqlOperator;
const UserRolesModel = require("./UserRolesModel");
const UserModel = db.define(
"users",
{
userId: {
field: "userId",
type: sqlOperator.UUID,
primaryKey: true,
defaultValue: sqlOperator.UUIDV4
},
firstName: {
field: "firstName",
type: sqlOperator.STRING(100),
require: true
},
lastName: {
field: "lastName",
type: sqlOperator.STRING(100),
},
email: {
field: "email",
type: sqlOperator.STRING(1025),
validate: {
isEmail: true
}
},
userName: {
field: "userName",
type: sqlOperator.STRING(1025),
},
phone: {
field: "phone",
type: sqlOperator.STRING(13),
},
photo: {
field: "photo",
type: sqlOperator.STRING(1024),
defaultValue: null,
validate: {
isUrl: true
}
},
studentDetails: {
field: "studentDetails",
type: sqlOperator.JSON,
defaultValue: null,
},
profession: {
field: "profession",
type: sqlOperator.STRING(13),
defaultValue: ""
},
},
{
tableName: "users",
timestamps: true,
indexes: [
{
unique: true,
fields: ["email"],
name: "user_email_unique_index"
},
{
unique: true,
fields: ["userName"],
name: "user_user_name_unique_index"
},
]
}
);
UserModel.associate = () => {
UserModel.hasMany(UserRolesModel, {
as: "roles"
});
UserModel.sync({ alter: true });
}
module.exports = UserModel;
This kind of issue usually occur when we try to compare mismatched data types. You cannot compare an integer with a varchar. PostgreSQL is strict and does not do any magic typecasting for you. I’m guessing SQLServer does typecasting automagically (which is a bad thing).
const phone = 9998886660;
UserModel.count({
where: {
phone: phone
}
});
[AdSense-B]
The above code throws operator does not exist: integer = character varying exception, because we are trying to compare integer with string. To fix this issue change as follows
const phone = "9998886660"; //this will fix the issue
UserModel.count({
where: {
phone: phone
}
});
[AdSense-A]
[AdSense-B]
[AdSense-A]
Complete Source Code for server side rendering in ReactJS using material-ui and redux is explained step by step here
[AdSense-B]
You can also see details about each code segment and download source code from github here
I found this wonderful video and found the meaning of life, you may be a programmer, a civil engineer, a car maker, a researcher, a teacher or a student whoever you may be, but one must listen to this talk by Prof. Devdas Menon, Department of Civil Engineering, IIT Madras
Some of the very interesting point taken out from this video are as follows
[AdSense-A]
George Calvin’s famouse quote in 80’s
The paradox of our time and history is that
We tall the buildings but short the temper,
wide our free ways but narrowed our view point
we spend more but we have less
we buy more but we enjoy less
we have bigger houses but smaller family
we have more knowledge but less judgement
we have more experts but yet more problems
we have more medicines but less wellness
we multiplied our positions but reduced our values
we talk too much , drive too fast , stay up too late, getup too tired, we have reached moon and back to earth but trouble crossing a road to meet a neighbour,
we have conquered outer space but not inner space
we have done larger things but not better
we have learnt to rush but not to wait
we have fast food but slow digestion
a big men but small character
too many young couple but more divorces
more entertainment but less happiness
MASLOW’s Hierarchy Of Needs
[AdSense-B]

Matthieu Ricard’s Quote
A French Scientist, who turned as tibetan monk
We all tried consciously or unconsciously, competently or clumsily , Passionately or calmly, adventurously or routinely to be Happier, Yet we more often confuse the genuine happiness with merely seeking enjoyable sensation. Happiness is state of inner fulfilment but not the gratification of inexhaustible desire for outer things. This is traditional wisdom.
Kabir Das Said it beautifully in 15th century in one of his famous doha as
कस्तूरी कुंडल बसे,मृग ढूँढत बन माही। ज्योज्यो घट– घट राम है,दुनिया देखें नाही ।।
Listen to this nice video by Prof. Devdas Menon, Department of Civil Engineering, IIT Madras
[AdSense-A]
java.lang.BootstrapMethodError: Exception from call site #30 bootstrap method
at org.apache.commons.lang3.Validate.notNull(Validate.java:225)
at org.apache.commons.lang3.reflect.FieldUtils.getAllFieldsList(FieldUtils.java:217)
at org.apache.commons.lang3.reflect.FieldUtils.getAllFields(FieldUtils.java:202)
at com.opencsv.bean.util.OpencsvUtils.determineMappingStrategy(OpencsvUtils.java:66)
at com.opencsv.bean.CsvToBeanBuilder.build(CsvToBeanBuilder.java:210)
at com.example.rkmmedialibrary.MainActivity.importCsv(MainActivity.java:95)
at com.example.rkmmedialibrary.MainActivity.onActivityResult(MainActivity.java:80)
at android.app.Activity.dispatchActivityResult(Activity.java:7454)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4353)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4402)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassCastException: Bootstrap method returned null
The issue is probably due to Java Version Mismatch, Kindly add below code in your build.gradle file
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Reference: SO Post
Let us first see how we can use include when we are joining 2 simple tables.
Note: If you are already aware of single join, then jump to section “Include” with multiple joins
Consider the following two tables,
User Table
const UserModel = db.define(
"users",
{
userId: {
field: "userId",
type: sqlOperator.UUID,
primaryKey: true,
defaultValue: sqlOperator.UUIDV4
},
firstName: {
field: "firstName",
type: sqlOperator.STRING(100),
require: true
},
lastName: {
field: "lastName",
type: sqlOperator.STRING(100),
},
email: {
field: "email",
type: sqlOperator.STRING(255),
validate: {
isEmail: true
}
},
{
tableName: "users",
timestamps: true
}
);
Notice Table
[AdSense-A]
const NoticesModel = db.define(
"notices",
{
noticeId: {
field: "noticeId",
type: sqlOperator.UUID,
primaryKey: true,
defaultValue: sqlOperator.UUIDV4
},
title : {
field: "title",
type: sqlOperator.STRING(250),
},
notice : {
field: "notice",
type: sqlOperator.TEXT,
}
},
{
tableName: "notices",
timestamps: true
}
);
NoticesModel.belongsTo(UserModel, {
foreignKey : {
name : "noticeBy",
allowNull: false
},
targetKey: "userId"
});
When we want to fetch the user who has posted the notice, we will use the following code,
const query ["include"] = [{model: UserModel}]
// query can include all some conditions required, this is out of scope of this tutorial, for the same you can check out this
const notices = await NoticeModel.findAll(query);
After executing the above findAll, we will get all the notices and the respective user who has created that.
In this section we will learn how to use when there are multiple join of the same table.
We will make some changes in the Notice table as follows,
const NoticesModel = db.define(
"notices",
{
noticeId: {
field: "noticeId",
type: sqlOperator.UUID,
primaryKey: true,
defaultValue: sqlOperator.UUIDV4
},
title : {
field: "title",
type: sqlOperator.STRING(250),
},
notice : {
field: "notice",
type: sqlOperator.TEXT,
}
},
{
tableName: "notices",
timestamps: true
}
);
NoticesModel.belongsTo(UserModel, {
foreignKey : {
name : "noticeBy",
allowNull: false
},
targetKey: "userId"
});
//Added one more new relation
NoticesModel.belongsTo(UserModel, {
foreignKey : {
name : "noticeTo",
allowNull: false
},
targetKey: "userId"
});
Now we will try to run the same above findAll, we will observe that neither noticeTo nor noticeBy will be filled.
What is happening here is Sequelize finds multiple userModels so it will not be sure which one to fetch.
[AdSense-B]
To solve the above issue we will have to make the following changes
const NoticesModel = db.define(
"notices",
{
noticeId: {
field: "noticeId",
type: sqlOperator.UUID,
primaryKey: true,
defaultValue: sqlOperator.UUIDV4
},
title : {
field: "title",
type: sqlOperator.STRING(250),
},
notice : {
field: "notice",
type: sqlOperator.TEXT,
}
},
{
tableName: "notices",
timestamps: true
}
);
NoticesModel.belongsTo(UserModel, {
foreignKey : {
name : "noticeBy",
allowNull: false
},
targetKey: "userId",
as : "noticedBy"
});
//Added one more new relation
NoticesModel.belongsTo(UserModel, {
foreignKey : {
name : "noticeTo",
allowNull: false
},
as: "noticedTo",
targetKey: "userId"
});
And in the find we will do this,
const query["include"] = [{model: UserModel, as: "noticedBy"}, {model: UserModel, as: "noticedTo"}]
const notices = await NoticeModel.findAll(query);
Once we add the above changes, both noticedBy and noticeTo will be filled. (Observe we have not kept the alias name same, we have changed them slightly).
uncaughtException: Naming collision between attribute ‘noticeTo’ and association ‘noticeTo’ on model notices. To remedy this, change either foreignKey or as in your association definition\nError: Naming collision between attribute ‘noticeTo’ and association ‘noticeTo’ on model notices
What does the above error mean?
It says that we have given same names to the attribute i.e foreign key and alias. We get this with the following code,
NoticesModel.belongsTo(UserModel, {
foreignKey: "noticeTo",
as: "noticeTo",
targetKey: "userId"
});
As we can see the highlighted rows, both have the same names. Solution to this is very simple, just rename alias to something else.
NoticesModel.belongsTo(UserModel, {
foreignKey: "noticeTo",
as: "noticedTo",
targetKey: "userId"
});
TADA!!! everything will work fine now.
[AdSense-A]
[AdSense-B]
A Video Tutorial on Server Side Rendering, which describes how exactly client side rendering happens, what are the benefits on Server Side Rendering.