How to connect the database to ember


#1

Hi! I am new to ember. I have lot of doubts on ember data like how to connect the database to ember and how to run the code with database. is it necessary to run any back end servers with ember server for working with back end.


#2

Hi @Santhoshi, hopefully I can help clear things up for you. Ember is a front-end framework only, and the ember serve command is meant only for development purposes. AFAIK any modern front-end framework will work like this, meaning it will require some sort of API or backend layer. Ember is not a framework intended for developing server-side code. It is, however, highly customizable so you can fit it onto whatever backend you need.

A production ember app will essentially require two servers, or at least a server that serves two different things:

  1. the Ember app itself (an html file, some js, css files and assets)
  2. the API endpoints that the Ember app uses for data

So the ‘ember serve’ command is meant only to fulfill item 1 above, and only for development purposes. To connect a database you’d either want to write your own server API or use something like Firebase or maybe PouchDB (@broerse could probably tell you more about that).

When you actually deploy a production ember app you would typically deploy to a static file service like Amazon S3 or use any other standard webserver with configuration for service a webapp, but again you would never use ember serve in production. It is merely a convenience for serving the webapp locally during development.


#3

@dknutsen Thanks! @Santhoshi Yes https://github.com/pouchdb-community/ember-pouch will let you talk to an in browser PouchDB server. This server can be synced with a CouchDB server like IBM cloudant or your own CouchDB. For testing you can just run PouchDB without a server. The Ember App can be deployed to the CouchDB database so you don’t need a web server. https://bloggr.exmer.com is deployed to a CouchDB server this way. (We are in the process of switching from martinic.cloudant.com to martinic.couchcluster.com so it can break in the next week)

Source for Bloggr Example https://github.com/broerse/ember-cli-blog


#4

@dknutsen thank you for reply.I got some idea on database but i need to know api server.Actually i working on mysql database.Is there any format for writing the api path to connect the database.


#5

Hi @Santhoshi, in order to manage the data you want to save you’ll need to use a backend framework like rails, phoenix or nodejs. These will let you save the information from the ember app to the database.

GoRails have a series which should walk you through this process. You can find it here.


#6

Hi @James-Byrne, I already installed nodejs framework but i don’t know how to connect the database.


#7

Ahh sorry @Santhoshi, in that case heres a tutorial on connecting a node app to a mysql db.


#8

@James-Byrne Thanks, can you provide tutorial on simple user login system using ember-php-my sql with REST adapters.


#9

@Santhoshi if you want to work with ember without having to worry about the whole server-side end of things, look into ember-cli-mirage