質問編集履歴
3
ソース修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,40 +13,12 @@
|
|
13
13
|
{"error":true,"data":{"message":"select count(distinct `company`.`id`) from `company` - ER_BAD_FIELD_ERROR: Unknown column 'company.id' in 'field list'"}
|
14
14
|
|
15
15
|
〇ソース
|
16
|
-
// 基本設定
|
17
|
-
var express = require('express');
|
18
|
-
var router = express.Router();
|
19
|
-
|
20
|
-
// MySQL設定
|
21
|
-
var mysql = require('mysql');
|
22
|
-
// node-configモジュールの読み込み
|
23
|
-
const config = require('config');
|
24
|
-
// DBの接続情報の読み込み
|
25
|
-
const dbConfig = config.get('db');
|
26
|
-
|
27
|
-
//bookshelf設定
|
28
|
-
var knex = require('knex')({
|
29
|
-
client: 'mysql',
|
30
|
-
connection: dbConfig
|
31
|
-
});
|
32
16
|
var Bookshelf = require('bookshelf')(knex);
|
33
17
|
Bookshelf.plugin('pagination');
|
34
18
|
var MyData = Bookshelf.Model.extend({
|
35
19
|
tableName: 'company'
|
36
20
|
});
|
37
21
|
|
38
|
-
// 初期アクセス時(GETアクセス)の処理
|
39
|
-
router.get('/', (req, res, next) => {
|
40
|
-
new MyData().orderBy('COMPANY_ID','DESC')
|
41
|
-
.fetchAll().then((collection) => {
|
42
|
-
var data = {
|
43
|
-
title: 'DB(Mysql)からデータ取得・一覧表示(bookshelf)',
|
44
|
-
content: collection.toArray()
|
45
|
-
};
|
46
|
-
res.render('dblistbook', data);
|
47
|
-
})
|
48
|
-
});
|
49
|
-
|
50
22
|
router.get('/:page', (req, res, next) => {
|
51
23
|
var pg = req.params.page;
|
52
24
|
pg *= 1;
|
2
ソース修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -65,18 +65,4 @@
|
|
65
65
|
});
|
66
66
|
});
|
67
67
|
|
68
|
-
router.post('/post',(req, res, next) => {
|
69
|
-
//1レコードのみ抽出時
|
70
|
-
new MyData().where('company_name', '=', req.body['company_name']).fetchAll().then((collection) => {
|
71
|
-
var data = {
|
72
|
-
title: 'DB(Mysql)からデータ取得・一覧表示(bookshelf)',
|
73
|
-
content: collection.toArray()
|
74
|
-
//1レコードのみ抽出時
|
75
|
-
//mydata: collection
|
76
|
-
};
|
77
|
-
console.log(req.body['company_name']);
|
78
|
-
res.render('dblistbook', data);
|
79
|
-
})
|
80
|
-
});
|
81
|
-
|
82
68
|
module.exports = router;
|
1
ソース追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,4 +10,73 @@
|
|
10
10
|
});
|
11
11
|
|
12
12
|
〇エラー
|
13
|
-
{"error":true,"data":{"message":"select count(distinct `company`.`id`) from `company` - ER_BAD_FIELD_ERROR: Unknown column 'company.id' in 'field list'"}
|
13
|
+
{"error":true,"data":{"message":"select count(distinct `company`.`id`) from `company` - ER_BAD_FIELD_ERROR: Unknown column 'company.id' in 'field list'"}
|
14
|
+
|
15
|
+
〇ソース
|
16
|
+
// 基本設定
|
17
|
+
var express = require('express');
|
18
|
+
var router = express.Router();
|
19
|
+
|
20
|
+
// MySQL設定
|
21
|
+
var mysql = require('mysql');
|
22
|
+
// node-configモジュールの読み込み
|
23
|
+
const config = require('config');
|
24
|
+
// DBの接続情報の読み込み
|
25
|
+
const dbConfig = config.get('db');
|
26
|
+
|
27
|
+
//bookshelf設定
|
28
|
+
var knex = require('knex')({
|
29
|
+
client: 'mysql',
|
30
|
+
connection: dbConfig
|
31
|
+
});
|
32
|
+
var Bookshelf = require('bookshelf')(knex);
|
33
|
+
Bookshelf.plugin('pagination');
|
34
|
+
var MyData = Bookshelf.Model.extend({
|
35
|
+
tableName: 'company'
|
36
|
+
});
|
37
|
+
|
38
|
+
// 初期アクセス時(GETアクセス)の処理
|
39
|
+
router.get('/', (req, res, next) => {
|
40
|
+
new MyData().orderBy('COMPANY_ID','DESC')
|
41
|
+
.fetchAll().then((collection) => {
|
42
|
+
var data = {
|
43
|
+
title: 'DB(Mysql)からデータ取得・一覧表示(bookshelf)',
|
44
|
+
content: collection.toArray()
|
45
|
+
};
|
46
|
+
res.render('dblistbook', data);
|
47
|
+
})
|
48
|
+
});
|
49
|
+
|
50
|
+
router.get('/:page', (req, res, next) => {
|
51
|
+
var pg = req.params.page;
|
52
|
+
pg *= 1;
|
53
|
+
if (pg < 1){ pg = 1; }
|
54
|
+
new MyData().fetchPage({page:pg, pageSize:3}).then((collection) => {
|
55
|
+
var data = {
|
56
|
+
title: 'DB(Mysql)からデータ取得・一覧表示(bookshelf)',
|
57
|
+
content: collection.toArray(),
|
58
|
+
pagination:collection.pagination
|
59
|
+
};
|
60
|
+
console.log(collection.pagination);
|
61
|
+
res.render('dblistbook', data);
|
62
|
+
})
|
63
|
+
.catch((err) => {
|
64
|
+
res.status(500).json({error: true, data: {message: err.message}});
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
router.post('/post',(req, res, next) => {
|
69
|
+
//1レコードのみ抽出時
|
70
|
+
new MyData().where('company_name', '=', req.body['company_name']).fetchAll().then((collection) => {
|
71
|
+
var data = {
|
72
|
+
title: 'DB(Mysql)からデータ取得・一覧表示(bookshelf)',
|
73
|
+
content: collection.toArray()
|
74
|
+
//1レコードのみ抽出時
|
75
|
+
//mydata: collection
|
76
|
+
};
|
77
|
+
console.log(req.body['company_name']);
|
78
|
+
res.render('dblistbook', data);
|
79
|
+
})
|
80
|
+
});
|
81
|
+
|
82
|
+
module.exports = router;
|