--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Use knexjs with nwjs
Hi Guys,--I'm a total n00b with regards to Node. I have some basic PHP skills with regards to connecting to MySQL databases, but I can't find any guides or tutorials which walk me through connecting to a MySQL database and retrieving data from it and listing it on the page.I have a very simple task. I have a database built using phpMyAdmin with a few tables within the database. I just need to connect to the database and display the required rows/data on the screen. Can anyone point me in the right direction?I've seen some guides talking about node.js and node-mysql modules. But these are totally throwing me off. Are they the same thing?I've been Googling for the last few days but can't find any guides which are easy to understand. :(
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
var knex = require('knex')({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
});knex('users').where({
first_name: 'Test',
last_name: 'User'
}).select('id').then(function(res){// do your work here, //you can console res or parse it as json object})To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
var knex = require('knex')({
client: 'mysql',
connection: {
host : 'localhost',
port : 3306,
user : 'user1',
password : 'password1',
database : 'testdb'
}
});
knex.select().table('categories');
--
SyntaxError: Unxepected end of inputknex.select('*').from('categories').debug() .then(function(rows) {console.log(rows);})
Try the above codevar knex = require('knex')({
client: 'mysql',
connection: {
host : 'localhost',
port : 3306,
user : 'user1',
password : 'password1',
database : 'testdb'
}
});
knex.select('*').from('categories').debug()
.then(function(rows) {console.log(rows);}){ __cid: '__cid1',
method: 'select',
options: undefined,
bindings: [],
sql: 'select * from `categories`' }
[ { id: 1, catName: 'Category 1' },
{ id: 2, catName: 'Category 2' },
{ id: 3, catName: 'Category 3' },
{ id: 4, catName: 'Category 4' },
{ id: 5, catName: 'Category 5' },.finally(function() { knex.destroy(); })
But I can't strip away the "id","#" and "catName" bits.--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Datbase: testdb
Table: categories
Data:
id catName
1 Category 1
2 Category 2
3 Category 3
4 Category 4
5 Category 5
var knex = require('knex')({
client: 'mysql',
connection: {
host : 'localhost',
port : 3306,
user : 'user1',
password : 'password1',
database : 'testdb'
}
});
knex.select('*').from('categories').debug()
.then(function(rows) {
for(var ix in rows){
console.log(rows[ix].catName);
}
})
.finally(function() {
knex.destroy();
})--
--
var knex = require('knex')({
client: 'mysql',
connection: {
host : 'localhost',
port : 3306,
user : 'user1',
password : 'password1',
database : 'testdb
}
});
knex.select('*').from('categories').debug()
.then(function(rows) {
var str = "";
for(var ix in rows){
str += "<button id='"+ix+"'>"+rows[ix].catName+"</button>";
}
document.body.innerHTML = str;
})
.finally(function() {
knex.destroy();
})--
document.body.innerHTML = str;
SyntaxError: Unexpected identifier--
Cool. Thanks Seth, but which files do you need Seth? I'm running the mysql database locally. Do u need that as well?
--
--
str += "<a href="'+rows[ix].catURL'"><button id='"+ix+"'>"+rows[ix].catName+"</button></a>";str += "<button id='"+ix+"' onclick="window.location.href='"'+rows[ix].catURL'"'">"+rows[ix].catName+"</button>";str += "<a href='"+rows[ix].catURL+"'><button id='"+ix+"'>"+rows[ix].catName+"</button></a>";--
You received this message because you are subscribed to the Google Groups "nw.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwjs-general...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
str += "<a href='"+rows[ix].classBtn+"' class='btn btn-lg btn-info'><id='"+ix+"'>"+rows[ix].catName+"</id></a>";