These are chat archives for quorrajs/quorrajs

31st
May 2016
Oliver Kurmis
@oliworx
May 31 2016 13:39 UTC
Hi, I go through the little tutorial at https://quorrajs.org/docs/v1/preface/quickstart.html . Here it is said "Using your preferred database administration tool, insert a few rows into your user table, and we'll use Waterline to retrieve them and pass them to our view." But how can I insert data when using the localDiskDb driver from the default install.
Harish
@harishanchu
May 31 2016 13:46 UTC
Ah, yes
You cannot use any tool to insert data when you use local disk db
even though you can manually edit sails disk storage file and add data
Oliver Kurmis
@oliworx
May 31 2016 13:49 UTC
ok, and what ist the file?
can you give an example?
Harish
@harishanchu
May 31 2016 13:52 UTC
sails disk storage file is located in projectroot/.tmp directory
You can create sample data using the user mdoel itself
User.create({email: 'me@example.com', password:'sdfdsafdasfsdf'}).exec(function createCB(err, created){ console.log('Created user with name ' + created.name); });
Oliver Kurmis
@oliworx
May 31 2016 13:56 UTC
should I put this line in a js file?
Harish
@harishanchu
May 31 2016 13:56 UTC
here is sample local disk db storage file : https://www.dropbox.com/s/lmvu0nq0f9t87mr/localDiskDb.db?dl=0
it should be named as localDiskDb.db inside .tmp directory
all good?
Oliver Kurmis
@oliworx
May 31 2016 14:05 UTC
not yet, the data is not loaded
TypeError (500)
/Users/oli/Projects/sandbox/members/resources/views/users.jade:5 3| block content 4| each val in users > 5| p= val.name 6| Cannot read property 'name' of null
I better try the mysql driver
Oliver Kurmis
@oliworx
May 31 2016 14:19 UTC
is there a way to access the entities in the terminal ?
Harish
@harishanchu
May 31 2016 14:19 UTC
sorry, I was away
if you put these lines of code User.create({email: 'me@example.com', password:'sdfdsafdasfsdf'}).exec(function createCB(err, created){ console.log('Created user with name ' + created.name); }); in the landing page route, it will create a user when each time you access landing page
what entities did you mean?
Oliver Kurmis
@oliworx
May 31 2016 14:21 UTC
user objects
i set up a mysql db now
Harish
@harishanchu
May 31 2016 14:21 UTC
ok
Oliver Kurmis
@oliworx
May 31 2016 14:22 UTC
i want to know, if the connection is working at least
is there something like rails console
?
Harish
@harishanchu
May 31 2016 14:24 UTC
we didn't setup nodejs repl with quorra-cli yet
but you can try it manually
got project root in terminal
execute command node
Oliver Kurmis
@oliworx
May 31 2016 14:25 UTC
ok
Harish
@harishanchu
May 31 2016 14:25 UTC
then execute
require('./index.js')
Now it will lift quorra server
after than models will be accessible from terminal
to query users execute User.find(function(){console.log(arguments)})
Oliver Kurmis
@oliworx
May 31 2016 14:28 UTC
I got an Error: listen EADDRINUSE :::3000 at ...
Harish
@harishanchu
May 31 2016 14:28 UTC
like this way you can create new entries too
its because there is something else running on port 3000
Oliver Kurmis
@oliworx
May 31 2016 14:28 UTC
ok, server was still running :)
Harish
@harishanchu
May 31 2016 14:32 UTC
did it work?
Oliver Kurmis
@oliworx
May 31 2016 14:32 UTC
ok, now I get a result set, but the emails are missing
Harish
@harishanchu
May 31 2016 14:33 UTC
hmm
Oliver Kurmis
@oliworx
May 31 2016 14:33 UTC
{ '0': null,
'1':
[ { remember_token: 'aaa', id: 1, createdAt: null, updatedAt: null },
{ remember_token: 'bbb', id: 2, createdAt: null, updatedAt: null },
{ remember_token: 'ccc', id: 3, createdAt: null, updatedAt: null },
{ remember_token: 'ddd', id: 4, createdAt: null, updatedAt: null } ] }
Harish
@harishanchu
May 31 2016 14:33 UTC
its because email is not set in model
how did you set all those data
?
try to execute this command
User.create({email: 'me@example.com', password:'sdfdsafdasfsdf'}).exec(function createCB(err, created){ console.log('Created user with email' + created.email); });
Oliver Kurmis
@oliworx
May 31 2016 14:34 UTC
I did not modify the User model
Harish
@harishanchu
May 31 2016 14:34 UTC
ok
Oliver Kurmis
@oliworx
May 31 2016 14:35 UTC
var User = {
attributes: {
email: {
required: true,
email: true
},
password: {
required: true
},
remember_token: 'string'
},
Harish
@harishanchu
May 31 2016 14:35 UTC
I mean records in your database don't have email value
Oliver Kurmis
@oliworx
May 31 2016 14:35 UTC
{ '0': null,
'1':
[ { remember_token: 'aaa', id: 1, createdAt: null, updatedAt: null },
{ remember_token: 'bbb', id: 2, createdAt: null, updatedAt: null },
{ remember_token: 'ccc', id: 3, createdAt: null, updatedAt: null },
{ remember_token: 'ddd', id: 4, createdAt: null, updatedAt: null },
{ remember_token: null,
id: 5,
createdAt: '2016-05-31T14:35:32.000Z',
updatedAt: '2016-05-31T14:35:32.000Z' } ] }
Harish
@harishanchu
May 31 2016 14:36 UTC
if you create a new recrod with the command above I pasted you will see
Oliver Kurmis
@oliworx
May 31 2016 14:37 UTC
but your email was inserted in my database table
Harish
@harishanchu
May 31 2016 14:38 UTC
is it?
Oliver Kurmis
@oliworx
May 31 2016 14:39 UTC
mysql> select * from user;
+----+---------+--------------------+----------------+---------------------+---------------------+----------------+
| id | name | email | password | createdAt | updatedAt | remember_token |
+----+---------+--------------------+----------------+---------------------+---------------------+----------------+
| 1 | oli | oliver@kurmis.com | NULL | NULL | NULL | aaa |
| 2 | steffen | steffen@kurmis.com | NULL | NULL | NULL | bbb |
| 3 | gitte | gitte@kurmis.com | NULL | NULL | NULL | ccc |
| 4 | ulli | ulli@kurmis.com | NULL | NULL | NULL | ddd |
| 5 | NULL | me@example.com | sdfdsafdasfsdf | 2016-05-31 16:35:32 | 2016-05-31 16:35:32 | NULL |
+----+---------+--------------------+----------------+---------------------+---------------------+----------------+
5 rows in set (0,00 sec)
strange
Harish
@harishanchu
May 31 2016 14:40 UTC
yup
Oliver Kurmis
@oliworx
May 31 2016 14:40 UTC
can I add name to the model?
ok, this works
i added name: 'string' to the User attributes

User.find(function(){console.log(arguments)});
undefined

{ '0': null,
'1':
[ { name: 'oli',
remember_token: 'aaa',
id: 1,
createdAt: null,
updatedAt: null }, ...

Harish
@harishanchu
May 31 2016 14:44 UTC
email is still not working
?
Oliver Kurmis
@oliworx
May 31 2016 14:45 UTC
yes, not working
Harish
@harishanchu
May 31 2016 14:45 UTC
are you able to insert record with User.create method
?
Oliver Kurmis
@oliworx
May 31 2016 14:46 UTC
Yes, I already did this
I will try to change it to email: 'string'
Harish
@harishanchu
May 31 2016 14:47 UTC
and insertion works?
I mean are you able to insert a record with email without error
and record gets create in mysql with email field value
?
Oliver Kurmis
@oliworx
May 31 2016 14:48 UTC
yes.
and now i get the emails
User.find(function(){console.log(arguments)});
undefined
{ '0': null,
'1':
[ { name: 'oli',
email: 'oliver@kurmis.com',
remember_token: 'aaa',
id: 1,
createdAt: null,
updatedAt: null }, ....
I changed the model like this: var User = {
attributes: {
name: 'string',
email: 'string',
password: {
required: true
},
remember_token: 'string'
},
looks like it only works with simple 'string'
password is missing too in my result set
Harish
@harishanchu
May 31 2016 14:50 UTC
let me run this in my machine and see
Oliver Kurmis
@oliworx
May 31 2016 14:51 UTC
now I changed all attributes to string and it works now
Oliver Kurmis
@oliworx
May 31 2016 15:16 UTC
this will not give a result set, right? : var users = User.find();
Harish
@harishanchu
May 31 2016 15:17 UTC
No it won't
find is asynchronous
I'm able to do database operation with sails-mysql properly
Screenshot from 2016-05-31 08:45:31.png
Screenshot from 2016-05-31 08:45:55.png
Screenshot from 2016-05-31 08:46:21.png
Oliver Kurmis
@oliworx
May 31 2016 15:23 UTC
but this is from the quickstart example:
var users = User.find();
res.view('users', {users: users});
so how can this work at all ?
Harish
@harishanchu
May 31 2016 15:25 UTC
Ah, sorry
That's a mistake
I will update the docs
Oliver Kurmis
@oliworx
May 31 2016 15:26 UTC
what to use instead ?
Harish
@harishanchu
May 31 2016 15:29 UTC
Please use:
User.find(function (err, users) { res.view('users', {users: users}); });
thanks for pointing it out
Oliver Kurmis
@oliworx
May 31 2016 15:36 UTC
ok, now it shows the users :)
Harish
@harishanchu
May 31 2016 15:36 UTC
:)
Updated the quick start guide
Oliver Kurmis
@oliworx
May 31 2016 15:37 UTC
nice!
still the problem with the email and password columns
this is my table:
mysql> show create table user\G
* 1. row *
Table: user
Create Table: CREATE TABLE user (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
name varchar(32) DEFAULT NULL,
email varchar(64) DEFAULT NULL,
password varchar(64) DEFAULT NULL,
createdAt datetime DEFAULT NULL,
updatedAt datetime DEFAULT NULL,
remember_token varchar(255) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4
1 row in set (0,00 sec)
can you execute show create table on your table too ?
Harish
@harishanchu
May 31 2016 16:17 UTC
Table name for a model will be its global identity for now
hence for User model table name will be User, not user
Soon I will change this to the lower-case, plural name of the model file
Oliver Kurmis
@oliworx
May 31 2016 16:18 UTC
so I have to rename my table now ?
Harish
@harishanchu
May 31 2016 16:18 UTC
I'm working on this
but I'm wondering from where did you get those data previously :)
Oliver Kurmis
@oliworx
May 31 2016 16:19 UTC
seems like quorra is still moving a lot
Harish
@harishanchu
May 31 2016 16:20 UTC
do you have another table named user
Oliver Kurmis
@oliworx
May 31 2016 16:20 UTC
no
Harish
@harishanchu
May 31 2016 16:20 UTC
or whether data is comming from mysql itsefl
Oliver Kurmis
@oliworx
May 31 2016 16:20 UTC
not, this where exactly the lines from my table
Harish
@harishanchu
May 31 2016 16:21 UTC
after installing sails-mysql did you change connection to sails-mysql configuration in database.js configuration file?
Oliver Kurmis
@oliworx
May 31 2016 16:21 UTC
but email and password are nullable in my table
yes:
'mysql': {
'adapter': 'sails-mysql',
'host': 'localhost',
'user': 'root',
'password': '',
'database': 'blacklisten'
},
Harish
@harishanchu
May 31 2016 16:22 UTC
did you use this inside model object
Oliver Kurmis
@oliworx
May 31 2016 16:23 UTC
??
this is my model:

var User = {
attributes: {
name: 'string',
email: 'string',
password: 'string',
remember_token: 'string'
},

migrate: 'drop',

/**
 * Get model remember token field name.
 * Used by quorra auth service.
 *
 * @returns {string}
 */
getRememberTokenName: function () {
    return 'remember_token';
}

};

module.exports = User;

Harish
@harishanchu
May 31 2016 16:24 UTC
after defining connection configuration did you specify it as default model connection
`
'model': {
    /*
     |--------------------------------------------------------------------------
     | Default Database Connection Name
     |--------------------------------------------------------------------------
     |
     | Here you may specify which of the database connections above you wish
     | to use as your default connection for all database work.
     |
     */

    'connection': 'mysql',`
Oliver Kurmis
@oliworx
May 31 2016 16:25 UTC
yes:
Harish
@harishanchu
May 31 2016 16:25 UTC
inside database.js file
Oliver Kurmis
@oliworx
May 31 2016 16:25 UTC
'model': {
    /*
     |--------------------------------------------------------------------------
     | Default Database Connection Name
     |--------------------------------------------------------------------------
     |
     | Here you may specify which of the database connections above you wish
     | to use as your default connection for all database work.
     |
     */

    'connection': 'mysql',
Harish
@harishanchu
May 31 2016 16:25 UTC
ok
Oliver Kurmis
@oliworx
May 31 2016 16:27 UTC
how did you create your table ?
Harish
@harishanchu
May 31 2016 16:32 UTC
I did create it from phpmyadmin
Oliver Kurmis
@oliworx
May 31 2016 16:33 UTC
with nullable email column ? or NOT NULL ?
Harish
@harishanchu
May 31 2016 16:36 UTC
mysql> show create table User\G
* 1. row *
Table: User
Create Table: CREATE TABLE User (
id int(11) NOT NULL AUTO_INCREMENT,
email varchar(30) NOT NULL,
password varchar(100) NOT NULL,
remember_token int(100) NOT NULL,
createdAt date NOT NULL,
updatedAt date NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
let me make it nullable and c what happens
I made it null and find donot return email
Harish
@harishanchu
May 31 2016 16:48 UTC
I think its a bug with sails-mysql
Harish
@harishanchu
May 31 2016 17:46 UTC
hi @oliworx
I have made table name as lower-case, plural name of the model file if no explicit table name is specified in the model file.
so in a new installation of quorra application, for example model User.js table name will be users by default
Oliver Kurmis
@oliworx
May 31 2016 18:26 UTC
ok, I'll try it again :)
Harish
@harishanchu
May 31 2016 19:45 UTC
:+1:
Oliver Kurmis
@oliworx
May 31 2016 20:28 UTC
why remember_token int(100) NOT NULL ?
Oliver Kurmis
@oliworx
May 31 2016 20:59 UTC
again no email or password in my result set
Oliver Kurmis
@oliworx
May 31 2016 21:05 UTC
ok, now I got it, you have to include type: string in the attributes of the model:
var User = {
attributes: {
    email: {
        required: true,
        email: true,
        type: 'string'
    },
    password: {
        type: 'string',
        required: true
    },
    remember_token: 'string'
},