Unhandled promise error: [object Promise]TypeError: this.db(...) is not a function
Unhandled promise error: [object Promise]TypeError: this.db(...) is not a function
Hi all,
I've just installed the trial version of DataTables Editor with Node.JS and am trying to run the examples.
When I run:
$ npm start
and open the URL the web page opens normally but there are no entries in the table just "Loading...".
In the console there is this error:
$ npm start
> datatables.net-editor-demo@1.7.4 start /home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4
> node index.js
DataTables Editor demo - navigate to http://localhost:8081/
Unhandled promise error: [object Promise]TypeError: this.db(...) is not a function
stack: TypeError: this.db(...) is not a function
at Editor.<anonymous> (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.ts:928:24)
at step (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.js:42:23)
at Object.next (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.js:23:53)
at fulfilled (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.js:14:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
Unhandled promise error: [object Promise]TypeError: this.db(...) is not a function
stack: TypeError: this.db(...) is not a function
at Editor.<anonymous> (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.ts:928:24)
at step (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.js:42:23)
at Object.next (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.js:23:53)
at fulfilled (/home/user/DataTables-Editor-Trial/Editor-NodeJS-1.7.4/node_modules/datatables.net-editor-server/dist/editor.js:14:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
It seems to be a problem with the database connection.
These are the steps I've followed:
1. $ npm install --save
2. Created with DB Browser for SQLite a new DB and pasted the SQL code from here:
https://editor.datatables.net/examples/sql/sqlite.sql.
The created tables seem to be OK.
3. Modified db.js:
var knex = require('knex')({
client: 'sqlite3',
connection: {
filename: "./myeditor.db"
},
useNullAsDefault: true
});
Any idea what I have done wrong?
This question has an accepted answers - jump to answer
Answers
I see now there are no records in the tables except in the "todo" table. I tried also with Valentina Studio and I get an error when I run the SQL:
14:34:03 Kernel error: Sqlite db "/home/user/DataTables-Editor-Trial/editor_db4.db": Error : "12 values for 10 columns".
Same error with PostgreSQL. I've loaded the postgres.sql file and tables and records seem to be OK.
Are you exporting the
knex
variable at all?The default db.js that I have is:
So for your use case it should be:
Then in the controller it should do something like:
Regards,
Allan
@allan : It works now for PostgreSQL! Many thanks!
I've changed db.js from this:
(which I found in the Knex.js docs:
https://knexjs.org/#Installation-client
)
to this:
I assume the same way would have worked for SQLite but there seems to be an issue with the provided SQL since both DB Browser for SQLite and Valentina Studio failed to create correctly all tables and records.