Mapping between Tables and Classes

class Human:
	def __init__(self, first_name, last_name, age):
		self.first_name = first_name
		self.last_name = last_name
		self.age = age

对应SQL schema

CREATE TABLE humans (
	id INTEGER PRIMARY KEY,
	first_name VARCHAR,
	last_name VARCHAR,
	age INTEGER
);

# Create instances or objects of the class
sarah = Human('Sarah', 'Silverman', 48)
bob = Human('Bob', 'Saget', 54)

对应 SQL

first_name last_name age
Sarah Silverman 48
Bob Saget 54

A SQL table column maps to an attribute on a class.
The table schema matches to the class definition of the class as a whole.
An row of the table match to records or objects that are instances of a class.


  • Tables map to classes.
  • Table records map to class objects.
  • Table columns map to class attributes.

猜你喜欢

转载自blog.csdn.net/BSCHN123/article/details/121220438