GithubHelp home page GithubHelp logo

productioncoder / objection-js-tutorial Goto Github PK

View Code? Open in Web Editor NEW
19.0 1.0 8.0 1.59 MB

Objection.js tutorial with Postgres and express that demonstrates migrations, seed data and eager loading

JavaScript 100.00%

objection-js-tutorial's Introduction

Objection.js Tutorial with Postgres and Express

This tutorial demonstrates how to connect to a Postgres database with Objection.js.

It also demonstrates how to create the database schema and how to create seed data with the knex.js migration tool.

Please help this repo with a โญ๏ธ if you find it useful! ๐Ÿ˜

This repository is contains the code for the Objection.js tutorial on Youtube

Objection.js tutorial

Please also check out my website at jangoebel.com

For updates, please follow @_jgoebel on Twitter.

How to run this application

This application needs a local Postgres instance.

Installing Postgres

On macOS you can install Postgres with Homebrew.

brew install postgresql

and start it with

brew services start postgres

You can stop Postgres with:

brew services stop postgres

For other operating systems, please check the Postgres website.

Database setup

Make sure to update the configuration app with your database credentials in the ../db/knexfile.js file. There you need to specify the user, password (per default no password required) and the database you want to connect to.

The default database we try to connect to is called objection_tutorial. Please make sure it exists in your local Postgres instance. You can either use a UI like PgAdmin to create the database or you can do so with psql

psql -h localhost -U <your-username> postgres

When installing locally, Postgres creates a database user with your operation system's username. You can run

whoami

on any Unix-like operating system to find out your user

Then you can create a new database with:

create database objection_tutorial;

Running the application

Once you have installed Postgres and updated the credentials in the ./db/knexfile.js, you can

npm run dev

This will:

  1. execute all existing database migrations located in ./db/migrations
  2. execute all seed files located in ./db/seed so you have some initial data
  3. start your server on port 8080 with nodemon to provide hot reload functionality

Additional Scripts

  • npm run down: undo last migration. Since we only have one migration at the moment this is equivalent to deleting all tables
  • npm run migrate: executes all migrations in ./db/migrations
  • npm run make-seed: create a new seed file

objection-js-tutorial's People

Contributors

productioncoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.