1

I'm an absolute beginner with Feathers, but it looks promising, so I'm trying to see if I can connect it to my SQL Server database, but I'm stuck right away.

I followed the docs and used feathers generate service, then edited my connection string, but then when I ran npm start it throws and error in src/models/sqlserver.model.js:

==> const sqlserver = sequelizeClient.define('sqlserver', {...
TypeError: Cannot read property 'define' of undefined

The generator edited default.json and added all these files:

/src
  mssql.js
  /services
    index.js
    sqlserver/
      sqlserver.filters.js
      sqlserver.hooks.js
      sqlserver.service.js

but the docs don't mention any of them (at least, not as I understood it), or what I need to change. I would think the generator is the easiest way to set this up, but it's confusing to me as the docs seem to ignore the use of the generator, and everything is in app.js.

Would appreciate any guidance anyone can provide for just setting up a basic SQL Server service in Feathers.

redOctober13
  • 3,662
  • 6
  • 34
  • 61

1 Answers1

2

This was indeed a bug that should be fixed in feathers-cli v2.0.4 (see pull request here). You can update using npm update feathers-cli -g and generating a new application.

Alternatively you can change your existing src/sequelize.js file where it says

app.set('mssqlClient', sequelize);

To

app.set('sequelizeClient', sequelize);

Which will should also solve the problem.

Daff
  • 43,734
  • 9
  • 106
  • 120
  • That did allow me to start the server after adding a sequelize service (named 'sql'), so thank you, that answers the first part of the question. But I'm doing the "Chat" guide and trying to use this service rather than the NeDB messages service, but hitting `localhost:3030/sql` just gives a 500 error. The API docs seem to have everything in app.js, so I'm still not sure how to actually test the database connection. Do others struggle with this, or do JS pros new to Feathers just know how to hook all this up without instructions? – redOctober13 Apr 19 '17 at 17:13
  • Why are you trying to hit the `/sql` endpoint? If you creates a `messages` service it's still `localhost:3030/messages` – Daff Apr 19 '17 at 17:31
  • that's just what I named the service when the generator asked for a name. I think part of the problem is that when I log out the connection details after this line in `mssql.js`: `const { port, hostname, username, password } = connection;`, it says username and password are undefined. The `url.parse()` function returns an object with an `auth` property with username and password, but no props with those names. – redOctober13 Apr 19 '17 at 17:37
  • Did you try creating a connection and running a query with Sequelize directly (http://docs.sequelizejs.com/en/v3/)? We don't have much of a chance to test against MSSQL so there may be issues with this setup. Probably easier to discuss if you can share your findings in a [new issue](https://github.com/feathersjs/feathers-sequelize/issues/new). – Daff Apr 19 '17 at 23:47