Skip to content

Latest commit

 

History

History
105 lines (66 loc) · 2.13 KB

File metadata and controls

105 lines (66 loc) · 2.13 KB
Error in user YAML: (<unknown>): could not find expected ':' while scanning a simple key at line 3 column 1
---
- oeasy Python 0518
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
本教程同步发布在: 

     个人网站: `https://oeasy.org` 
     蓝桥云课: `https://www.lanqiao.cn/courses/3584` 
     GitHub: `https://github.com/overmind1980/oeasy-python-tutorial` 
     Gitee: `https://gitee.com/overmind1980/oeasypython` 
---

sqlalchemy

回忆

  • 次安装了
    • postgres数据库
    • sqlalchemy包

图片描述

  • sqlalchemy如何对postgresql数据库点石成金呢?

确认环境

  • 确认服务、库、表都ok

图片描述

  • 开始编辑py文件
    • 尝试连接

观察文档

图片描述

  • 什么是引擎呢?

引擎

  • engine

图片描述

  • 自己能够跑起来的东西
  • 带动整个车船运动的核心

照猫画虎

from sqlalchemy import create_engine
engine = create_engine("sqlite+pysqlite:///:memory:", echo=True)
  • 这个代码会建立一个在内存中的引擎

图片描述

  • 可以建立一个postgresql的引擎吗?

搜索

  • 貌似可以建立一个pg的引擎

图片描述

  • 使用postgres+psycopg2作为驱动
  • 字符串好长
  • 这都什么含义呢?

具体含义

  • 驱动
  • 用户名
  • 密码
  • 主机地址和端口
  • 数据库名称

图片描述

  • postgres的密码还得修改一下

修改密码

图片描述

  • 运行时报错

图片描述

安装psycopg2

图片描述

  • 运行不报错
  • 说明引擎已经可以发动起来了

总结

  • 我们下次再说

  • 本文来自 oeasy Python 系统教程。
  • 想完整、扎实学 Python,
  • 搜索 oeasy 即可。