Code Monkey home page Code Monkey logo

node-bookshelfjs-examples's Introduction

BookshelfJS Example

It doesn't look like anyone has done a full or semi-fledged example of how to use BookshelfJS in something like Express.

Most examples have all the models in the same file. This obviously won't work well if you're dealing with a larger app. So here is an attempt at using BookshelfJS in such a manner.

Database Schema

In this example, I used a MySQL database with the following schema:

Database schema

It's your classic Twitter clone, stripped down quite a bit.

We're not going to do a UI or validation. In fact, this example will only implement about half a REST API.

As you can see, we will have fairly standard one-to-many relationship and then a more complex many-to-many relationship via a join/bridge table.

An additional twist is the fact that both sides of the relationship are User models.

For clarity: In the Followers table, follower is the user ID of the user initiating the action while followee is the user ID of the person being acted upon. So when Alice follows Bob, Alice's ID is the follower and Bob's ID is the followee.

Okay - go look in src/app.js and read the comments.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.