Search This Blog

Featured Post

Machine Learning, Big Data, AI, Deep Learning

Monday, April 30, 2018

01/05/2018 Database

Dealing with resistance to change

ADKAR

Awareness
Desire
Knowledge
Ability
Reinforcement

Object-oriented analysis

-----
Class
-----
Description
-----
Object
-----

Monday, April 23, 2018

24/4/2018 SQLAlchemy


Flow of building connection with database via SQLAlchemy

Create Engine


Step

Key Code

Inspect

Connecting
>>> from sqlalchemy import create_engine
>>> engine = create_engine('sqlite:///:memory:', echo=True)
Map Declare
>>> from sqlalchemy.ext.declarative import declarative_base
>>> Base = declarative_base()
>>> from sqlalchemy import Column, Integer, String
>>> class User(Base):
...     __tablename__ = 'users'
...
...     id = Column(Integer, primary_key=True)
...     name = Column(String)
...     fullname = Column(String)
...     password = Column(String)
...
...     def __repr__(self):
...        return "<User(name='%s', fullname='%s', password='%s')>" % (
...                             self.name, self.fullname, self.password)
>>> User.__table__ 
Table('users', MetaData(bind=None),
  Column('id', Integer(), table=<users>, primary_key=True, nullable=False),
  Column('name', String(), table=<users>),
  Column('fullname', String(), table=<users>),
  Column('password', String(), table=<users>), schema=None)

Tuesday, April 17, 2018

18/4/2018 SQLAlchemy

Engine



To connect a database, use create_engine() from sqlalchemy. The create_engine() function produce an engine object based on a URL. The URLs follow RFC-1738.


>>>engine = create_engine(dialect+driver://username:password@host:port/database)
The above engine creates a Dialect object tailored towards the database and creates a Pool object which establish a DBAPI connection. However, it's first still not yet established until  Engine.connect()  method is called or an operation which is dependent on this method such as Engine.execute() is invoked.

Monday, April 16, 2018

17/04/2018 SQLAlchemy

SQLAlchemy

Consists of two components
  • Core = a fully featured SQL abstraction toolkit, providing a smooth layer of abstraction over a wide variety of DBAPI implementations and behaviors, as well as a SQL Expression Language which allows expression of the SQL language via generative Python expressions
  • ORM = Object Relational Mapper

16/04/2018 Request, Idea

Requests

Flask requests used Requests library from python. Request is terms from HTTP/1.1. HTTP/1.1 is defined under RFC 2616.

HTTP messages consist of requests from client to server and responses from server to client.

Request and Response messages use the generic message format of RFC 822 for transferring entities (the payload of the message). Both types of message consist of a start-line, zero or more header fields (also known as "headers"), an empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields, and possibly a message-body.

HTTP header fields, which include general-header, request-header, response-header, and entity-header fields, follow the same generic format as that given in Section 3.1 of RFC 822. Each header field consists of a name followed by a colon (":") and the field value.

The message-body (if any) of an HTTP message is used to carry the entity-body associated with the request or response.

There are a few header fields which have general applicability for both request and response messages, but which do not apply to the entity being transferred. These header fields apply only to the message being transmitted.

general-header included Cache-Control, Connection, Date, Pragma, Trailer, Transfer Encoding, Upgrade, Via, Warning.

Idea

Thinking of creating a logbook like webpage to record learning log and sharing knowledge. Generally idea is the page would separate into two parts. Left part is the main content and the right part is the log or comment. The log or comment on the right generally show in one sheet but related with the different part on the left with a linked line.