Git Product home page Git Product logo

crud_flask_postgresql's Introduction

simplinnovation

Basic CRUD: Flask & PostgreSQL

  1. Activate PostgreSQL server:

    $ cd C:\Program Files\PostgreSQL\10\bin
    $ psql -U postgres
      Password for user postgres: <insert password here>

  1. Create a database on PostgreSQL, my database name is "lin_flask":

    postgres=#  CREATE DATABASE lin_flask;
    postgres=#  \l 
    postgres=#  \c lin_flask

  1. Create a "users" table on "lin_flask" database:

    lin_flask=#  CREATE TABLE users(
                 id SERIAL PRIMARY KEY,
                 name VARCHAR(255),
                 age VARCAR(255)
                 );
    lin_flask=#  \d

  1. Clone this repo. Insert your database URI to database.yaml file, then install all the packages needed. In this project I'm using flask, flask_cors, flask_mysqldb, Flask-SQLAlchemy & psycopg2:
    $ git clone https://github.com/LintangWisesa/CRUD_Flask_PostgreSQL.git
    $ cd CRUD_Flask_PostgreSQL
    $ pip install flask flask_cors Flask-SQLAlchemy psycopg2

  1. Run the server file. Make sure your PostgreSQL server is still running. Your application server will run locally at http://localhost:5000/ :
    $ python app.py

  1. Give a request to the server. You can use Postman app:

    See the opening screen (home.html)

    GET /

    Post a data to database:

    POST /data
    body request: {name:"x", age:"y"}

    Get all data & specific data by id:

    GET /data
    GET /data/{:id}

    Update a data by id:

    PUT /data/{:id}
    body request: {name:"x", age:"y"}

    Delete a data by id:

    DELETE /data/{:id}

  1. Enjoy your code! ๐Ÿ˜Ž๐Ÿ‘Œ

See also:

Lintang Wisesa ๐Ÿ’Œ [email protected]

Facebook | Twitter | Google+ | Youtube | :octocat: GitHub | Hackster

crud_flask_postgresql's People

Contributors

lintangwisesa 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.