Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
financial-system
Project
Project
Details
Activity
Releases
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
Open sidebar
xianyang
financial-system
Commits
995e2932
Commit
995e2932
authored
Feb 07, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
07fab79d
Pipeline
#413
canceled with stages
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
28 deletions
+30
-28
financial-system.iml
.idea/financial-system.iml
+1
-0
__init__.py
app/users/__init__.py
+3
-0
crud.py
app/users/crud.py
+10
-10
models.py
app/users/models.py
+11
-11
db.py
core/storage/db.py
+5
-6
requirements.txt
requirements.txt
+0
-1
No files found.
.idea/financial-system.iml
View file @
995e2932
...
...
@@ -3,6 +3,7 @@
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
>
<excludeFolder
url=
"file://$MODULE_DIR$/fast_api"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/fs-env"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
...
...
app/users/__init__.py
View file @
995e2932
import
pymysql
pymysql
.
install_as_MySQLdb
()
\ No newline at end of file
app/users/crud.py
View file @
995e2932
...
...
@@ -24,13 +24,13 @@ def create_user(db: Session, user: schemas.UserCreate):
return
db_user
def
get_items
(
db
:
Session
,
skip
:
int
=
0
,
limit
:
int
=
100
):
return
db
.
query
(
models
.
Item
)
.
offset
(
skip
)
.
limit
(
limit
)
.
all
()
def
create_user_item
(
db
:
Session
,
item
:
schemas
.
ItemCreate
,
user_id
:
int
):
db_item
=
models
.
Item
(
**
item
.
dict
(),
owner_id
=
user_id
)
db
.
add
(
db_item
)
db
.
commit
()
db
.
refresh
(
db_item
)
return
db_item
#
def get_items(db: Session, skip: int = 0, limit: int = 100):
#
return db.query(models.Item).offset(skip).limit(limit).all()
#
#
#
def create_user_item(db: Session, item: schemas.ItemCreate, user_id: int):
#
db_item = models.Item(**item.dict(), owner_id=user_id)
#
db.add(db_item)
#
db.commit()
#
db.refresh(db_item)
#
return db_item
app/users/models.py
View file @
995e2932
...
...
@@ -8,19 +8,19 @@ class User(Base):
__tablename__
=
"users"
id
=
Column
(
Integer
,
primary_key
=
True
,
index
=
True
)
email
=
Column
(
String
,
unique
=
True
,
index
=
True
)
hashed_password
=
Column
(
String
)
email
=
Column
(
String
(
50
)
,
unique
=
True
,
index
=
True
)
hashed_password
=
Column
(
String
(
100
)
)
is_active
=
Column
(
Boolean
,
default
=
True
)
items
=
relationship
(
"Item"
,
back_populates
=
"owner"
)
class
Item
(
Base
):
__tablename__
=
"items"
id
=
Column
(
Integer
,
primary_key
=
True
,
index
=
True
)
title
=
Column
(
String
,
index
=
True
)
description
=
Column
(
String
,
index
=
True
)
owner_id
=
Column
(
Integer
,
ForeignKey
(
"users.id"
))
owner
=
relationship
(
"User"
,
back_populates
=
"items"
)
\ No newline at end of file
# class Item(Base):
# __tablename__ = "items"
#
# id = Column(Integer, primary_key=True, index=True)
# title = Column(String, index=True)
# description = Column(String, index=True)
# owner_id = Column(Integer, ForeignKey("users.id"))
#
# owner = relationship("User", back_populates="items")
\ No newline at end of file
core/storage/db.py
View file @
995e2932
# encoding:utf-8
'''
创建数据库连接引擎
'''
"""创建数据库连接引擎"""
from
sqlalchemy
import
create_engine
from
sqlalchemy.ext.declarative
import
declarative_base
...
...
@@ -19,9 +17,10 @@ SQLALCHEMY_DATABASE_URL = f'sqlite:///{modul_path}/sql_app.db'
# SQLALCHEMY_DATABASE_URL = f'mysql://{env.DATABASE_USER}:{env.DATABASE_PWD}@{env.DATABASE_URI}'
# connect_args={'check_same_thread': False} 仅仅在使用 sqlite数据库时有用
engine
=
create_engine
(
SQLALCHEMY_DATABASE_URL
,
encoding
=
'utf-8'
,
echo
=
True
,
connect_args
=
{
'check_same_thread'
:
False
}
)
# engine = create_engine(
# SQLALCHEMY_DATABASE_URL, encoding='utf-8', echo=True, connect_args={'check_same_thread': False}
# )
engine
=
create_engine
(
'mysql+mysqldb://data_center:KCMBfAjeJhbJXsSe@43.138.132.9:3398/fj-data-center'
)
# 数据库 session 类,用于创建 session 实例
# autoflush 是指发送数据库语句到数据库,但数据库不一定执行写入到磁盘
...
...
requirements.txt
View file @
995e2932
...
...
@@ -5,7 +5,6 @@ fastapi==0.89.1
greenlet
==2.0.2
h11
==0.14.0
idna
==3.4
jose
==1.0.0
passlib
==1.7.4
pydantic
==1.10.4
sniffio
==1.3.0
...
...
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