質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

SQL

SQL(Structured Query Language)は、リレーショナルデータベース管理システム (RDBMS)のデータベース言語です。大きく分けて、データ定義言語(DDL)、データ操作言語(DML)、データ制御言語(DCL)の3つで構成されており、プログラム上でSQL文を生成して、RDBMSに命令を出し、RDBに必要なデータを格納できます。また、格納したデータを引き出すことも可能です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

Q&A

2回答

3533閲覧

knex.jsでDBを作りたいのですが、うまくいきません!

iwanharts

総合スコア32

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

SQL

SQL(Structured Query Language)は、リレーショナルデータベース管理システム (RDBMS)のデータベース言語です。大きく分けて、データ定義言語(DDL)、データ操作言語(DML)、データ制御言語(DCL)の3つで構成されており、プログラム上でSQL文を生成して、RDBMSに命令を出し、RDBに必要なデータを格納できます。また、格納したデータを引き出すことも可能です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

0グッド

0クリップ

投稿2016/05/01 11:45

###前提・実現したいこと
node.jsでサーバサイドを作りたくて、knex.jsでDBを管理したい

###発生している問題・エラーメッセージ

$ knex migrate:make create_user とコマンド入力しても以下のようなエラーが出る $ knex migrate:make create_user /Users/hiro/Documents/project/nodejs/test3/knexfile.js:14 tableName: 'knex_migrations' ^^^^^^^^^ SyntaxError: Unexpected identifier at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17) at initKnex (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/lib/bin/cli.js:51:16) at Command.<anonymous> (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/lib/bin/cli.js:98:15) at Command.listener (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/node_modules/commander/index.js:301:8) at Command.emit (events.js:110:17) at Command.parseArgs (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/node_modules/commander/index.js:615:12) at Command.parse (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/node_modules/commander/index.js:458:21) at Liftoff.invoke (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/lib/bin/cli.js:143:13) at Liftoff.<anonymous> (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/node_modules/liftoff/index.js:181:16) at module.exports (/Users/hiro/.nvm/versions/node/v0.12.9/lib/node_modules/knex/node_modules/flagged-respawn/index.js:17:3)

###該当のソースコード

knexfile.js

1// Update with your config settings. 2 3module.exports = { 4 5 development: { 6 client: 'postgresql', 7 connection: { 8 database: 'my_db', 9 user: 'username', 10 password: 'password' 11 }, 12 migrations: { 13 directory: './db/migrations' 14 tableName: 'knex_migrations' 15 } 16 }, 17 18 staging: { 19 client: 'postgresql', 20 connection: { 21 database: 'my_db', 22 user: 'username', 23 password: 'password' 24 }, 25 pool: { 26 min: 2, 27 max: 10 28 }, 29 migrations: { 30 directory: './db/migrations' 31 tableName: 'knex_migrations' 32 } 33 }, 34 35 production: { 36 client: 'postgresql', 37 connection: { 38 database: 'my_db', 39 user: 'username', 40 password: 'password' 41 }, 42 pool: { 43 min: 2, 44 max: 10 45 }, 46 migrations: { 47 tableName: 'knex_migrations' 48 } 49 } 50 51}; 52

###補足情報(言語/FW/ツール等のバージョンなど)
http://qiita.com/YoshiyukiKato/items/59c9ac742536d706b322
上のサイトを参考に作成していました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHERRY

2016/05/02 00:16 編集

データベースは、PostgreSQL を使われいるのですね。 データベースのパッケージは、インストール済みですか?
iwanharts

2016/05/02 04:20

pgをインストールしました!
guest

回答2

0

development: { client: 'postgresql', connection: { database: 'my_db', user: 'username', password: 'password' }, migrations: { directory: './db/migrations' tableName: 'knex_migrations' } },

エラーメッセージとコードを見る限り、migrationsの中身のカンマが抜けているように見えます。

migrations: { directory: './db/migrations', tableName: 'knex_migrations' }

こうではないでしょうか

投稿2016/05/02 04:26

編集2016/05/02 04:27
attakei

総合スコア2738

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

iwanharts

2016/05/02 04:34

あ、すいません!それには自分で気づいて直しました!
guest

0

http://knexjs.org/ を見てみると

npm install knex --save npm install pg --save

で、データベースライブラリをインストールして、

client: 'pg',

と client は、pg で設定していますが、参照されている Qiita では、postgresql になっていますね。

client のところは、データベース用のパッケージ名と思いますので、こちらの設定に変更したらどうなりますか?

投稿2016/05/02 00:22

編集2016/05/02 00:23
CHERRY

総合スコア25171

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

iwanharts

2016/05/02 04:19

データベースライブラリをインストールしてみましたが、うまくいきません。 以下エラーです ``` HIROYUKI-no-MacBook-Air:test3 hiro$ knex migrate:make create_user Using environment: development Knex:Error Pool2 - Error: connect ECONNREFUSED Knex:Error Pool2 - Error: connect ECONNREFUSED Created Migration: /Users/hiro/Documents/project/nodejs/test3/db/migrations/20160502131123_create_user.js HIROYUKI-no-MacBook-Air:test3 hiro$ knex migrate:latest Using environment: development Knex:warning - Pool2 - Error: Pool was destroyed Knex:Error Pool2 - Error: connect ECONNREFUSED Error: Pool was destroyed at Pool._destroyPool (/Users/hiro/Documents/project/nodejs/test3/node_modules/pool2/lib/pool.js:548:20) at Pool.<anonymous> (/Users/hiro/Documents/project/nodejs/test3/node_modules/pool2/lib/pool.js:465:18) at Pool.<anonymous> (/Users/hiro/Documents/project/nodejs/test3/node_modules/pool2/lib/pool.js:505:17) at tryCatcher (/Users/hiro/Documents/project/nodejs/test3/node_modules/bluebird/js/main/util.js:26:23) at Promise.errorAdapter (/Users/hiro/Documents/project/nodejs/test3/node_modules/bluebird/js/main/nodeify.js:36:34) at Promise._settlePromiseAt (/Users/hiro/Documents/project/nodejs/test3/node_modules/bluebird/js/main/promise.js:579:21) at Promise._settlePromises (/Users/hiro/Documents/project/nodejs/test3/node_modules/bluebird/js/main/promise.js:697:14) at Async._drainQueue (/Users/hiro/Documents/project/nodejs/test3/node_modules/bluebird/js/main/async.js:123:16) at Async._drainQueues (/Users/hiro/Documents/project/nodejs/test3/node_modules/bluebird/js/main/async.js:133:10) at Immediate.Async.drainQueues [as _onImmediate] (/Users/hiro/Documents/project/nodejs/test3/node_modules/bluebird/js/main/async.js:15:14) at processImmediate [as _immediateCallback] (timers.js:367:17) HIROYUKI-no-MacBook-Air:test3 hiro$ ```
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問