Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DA-Platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
文档服务地址:
http://47.92.0.57:3000/
周报索引地址:
http://47.92.0.57:3000/s/NruNXRYmV
Open sidebar
Berlin
DA-Platform
Commits
f4ede532
Commit
f4ede532
authored
Jun 24, 2020
by
李景熙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改上传文件的相关代码,将数据库配置统一移到model文件中
parent
29108bba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
49 deletions
+1
-49
model.py
DAPlatform/dao/model.py
+1
-49
No files found.
DAPlatform/dao/model.py
View file @
f4ede532
from
peewee
import
*
from
peewee
import
*
from
pymongo
import
MongoClient
import
datetime
mysql
=
MySQLDatabase
(
mysql
=
MySQLDatabase
(
'test'
,
'test'
,
...
@@ -9,50 +7,4 @@ mysql = MySQLDatabase(
...
@@ -9,50 +7,4 @@ mysql = MySQLDatabase(
passwd
=
'root'
,
passwd
=
'root'
,
charset
=
'utf8'
charset
=
'utf8'
)
)
# 连接mysql数据库
mysql
.
connect
()
# mysql.connect();
# 连接mongodb数据库
client
=
MongoClient
(
'mongodb://root:mongodb@localhost:27017'
)
class
MysqlBaseModel
(
Model
):
# 内部类
class
Meta
:
database
=
mysql
;
# 每一个继承BaseModel类的子类都是连接db表
class
User
(
MysqlBaseModel
):
username
=
CharField
(
unique
=
True
);
# 每个属性都是一个表字段
class
Tweet
(
MysqlBaseModel
):
user
=
ForeignKeyField
(
User
,
related_name
=
'tests'
);
message
=
TextField
();
created_date
=
DateTimeField
(
default
=
datetime
.
datetime
.
now
);
is_published
=
BooleanField
(
default
=
True
);
if
__name__
==
'__main__'
:
# mysql操作示例
# User.create_table(); 创建User表
# Tweet.create_table(); 创建Tweet表
# 添加
# user = User.create(username="tom")
# Tweet.create(user=user, message="this is test msg")
# # 查询
# t = Tweet.get(message="this is test msg")
# print(t.user_id)
# print(t.created_date)
# print(t.is_published)
# mongodb操作示例
mongodb
=
client
[
'test'
]
collection
=
mongodb
[
'testcollection'
]
.
find
()
for
t
in
collection
:
print
(
t
)
col
=
mongodb
[
'test1'
]
image
=
{
'onepic'
:
'1.jpg'
,
'twopic'
:
'2.jpg'
,
'threepic'
:
'3.jpg'
}
aim
=
{
'name'
:
'test_1'
,
'document'
:
'this is test msg!'
,
'image'
:
image
}
col
.
insertone
(
aim
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment