Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
evm-store
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
wanli
evm-store
Commits
e3e9ca7a
Commit
e3e9ca7a
authored
Jun 16, 2021
by
wanli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
打通数据库
parent
580d911d
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
421 additions
and
103 deletions
+421
-103
tools/build_out/application/app.py
tools/build_out/application/app.py
+3
-0
tools/build_out/application/config.py
tools/build_out/application/config.py
+10
-6
tools/build_out/controllers/app.py
tools/build_out/controllers/app.py
+2
-2
tools/build_out/controllers/area.py
tools/build_out/controllers/area.py
+17
-8
tools/build_out/controllers/login.py
tools/build_out/controllers/login.py
+2
-2
tools/build_out/controllers/package.py
tools/build_out/controllers/package.py
+2
-2
tools/build_out/controllers/user.py
tools/build_out/controllers/user.py
+2
-2
tools/build_out/models/__init__.py
tools/build_out/models/__init__.py
+31
-2
tools/build_out/models/app.py
tools/build_out/models/app.py
+11
-11
tools/build_out/models/area.py
tools/build_out/models/area.py
+9
-7
tools/build_out/models/base.py
tools/build_out/models/base.py
+5
-2
tools/build_out/models/login.py
tools/build_out/models/login.py
+6
-6
tools/build_out/models/package.py
tools/build_out/models/package.py
+10
-10
tools/build_out/models/user.py
tools/build_out/models/user.py
+11
-11
tools/build_out/tests/test_sqlalchemy_sqlite.py
tools/build_out/tests/test_sqlalchemy_sqlite.py
+100
-0
tools/build_out/views/area.py
tools/build_out/views/area.py
+14
-7
tools/build_out/webcreator/log.py
tools/build_out/webcreator/log.py
+1
-1
tools/config.json
tools/config.json
+18
-3
tools/gen_code.py
tools/gen_code.py
+7
-0
tools/resources/application/app.py
tools/resources/application/app.py
+3
-0
tools/resources/application/config.py
tools/resources/application/config.py
+10
-6
tools/resources/models/__init__.py
tools/resources/models/__init__.py
+31
-2
tools/resources/tests/test_sqlalchemy_sqlite.py
tools/resources/tests/test_sqlalchemy_sqlite.py
+100
-0
tools/resources/webcreator/log.py
tools/resources/webcreator/log.py
+1
-1
tools/templates/base.tpl
tools/templates/base.tpl
+7
-4
tools/templates/controller.tpl
tools/templates/controller.tpl
+5
-5
tools/templates/model.tpl
tools/templates/model.tpl
+3
-3
No files found.
tools/build_out/application/app.py
View file @
e3e9ca7a
...
...
@@ -98,7 +98,10 @@ def create_app(config):
# 自定义abort 400 响应数据格式
flask_restful
.
abort
=
_custom_abort
# 数据库初始化
# db.app = app
db
.
init_app
(
app
)
# 创建表
db
.
create_all
()
# 注册蓝图
from
views
import
api_v1
app
.
register_blueprint
(
api_v1
,
url_prefix
=
'/api/v1'
)
...
...
tools/build_out/application/config.py
View file @
e3e9ca7a
...
...
@@ -32,13 +32,15 @@ class ProductionConfig(object):
MYSQL_PORT
=
3306
MYSQL_USER
=
'debian-sys-maint'
MYSQL_PWD
=
'XMigC2B2uugnv18y'
SQLALCHEMY_BINDS
=
"sqlite:////test.db"
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
SQLALCHEMY_BINDS
=
{
'app-store'
:
'sqlite:///../test.db'
}
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
def
__init__
(
self
):
super
()
.
__init__
()
self
.
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
self
.
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
class
DevelopConfig
(
object
):
...
...
@@ -66,15 +68,17 @@ class DevelopConfig(object):
MYSQL_PORT
=
3306
MYSQL_USER
=
'debian-sys-maint'
MYSQL_PWD
=
'XMigC2B2uugnv18y'
SQLALCHEMY_BINDS
=
"sqlite:////test.db"
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
SQLALCHEMY_BINDS
=
{
'app-store'
:
'sqlite:///../test.db'
}
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
SQLALCHEMY_TRACK_MODIFICATIONS
=
True
SQLALCHEMY_ECHO
=
False
def
__init__
(
self
):
super
()
.
__init__
()
self
.
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
self
.
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
if
MODE
==
'production'
:
config
=
ProductionConfig
()
...
...
tools/build_out/controllers/app.py
View file @
e3e9ca7a
...
...
@@ -12,7 +12,7 @@ class AppResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AppModel
.
a
reaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AppModel
.
a
pp_name
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
@@ -20,7 +20,7 @@ class AppResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AppModel
.
a
reaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
AppModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AppModel
.
a
pp_name
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
tools/build_out/controllers/area.py
View file @
e3e9ca7a
from
datetime
import
datetime
from
application.app
import
db
from
models.area
import
AreaModel
from
models
import
engine
,
BaseModel
from
webcreator.log
import
logger
from
webcreator.response
import
ResponseCode
,
response_result
...
...
@@ -10,37 +11,45 @@ class AreaResource(object):
def
get
(
self
,
params
):
# handle business
logger
.
warn
(
"============================>"
)
logger
.
warn
(
params
)
# filters = [AreaModel.is_delete==False]
# result = AreaModel.query.filter(*filters).order_by(AreaModel.areaId).paginate(params.get('page', 1), params.get('pageSize', 10), error_out=False)
result
=
[]
filters
=
[
AreaModel
.
is_delete
==
False
]
logger
.
warn
(
"/////////////////////////////"
)
logger
.
warn
(
"<<<<<<<<>>>>>>>>"
)
result
=
db
.
session
.
query
(
AreaModel
)
.
filter
()
.
order_by
(
AreaModel
.
create_at
)
.
all
()
logger
.
warn
(
result
)
logger
.
warn
(
"|||||||||||||||||||||||||||||"
)
return
params
return
result
def
getList
(
self
,
params
):
# handle business
logger
.
warn
(
params
)
filters
=
[]
# result = AreaModel.query.filter(AreaModel.is_delete==False).order_by(AreaModel.create_at).all()
result
=
AreaModel
.
query
.
filter
(
*
filters
)
.
order_by
(
AreaModel
.
areaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
logger
.
warn
(
result
)
logger
.
warn
(
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
)
return
result
def
post
(
self
,
params
,
jwt
=
None
):
# handle business
result
=
AreaModel
.
query
.
filter
(
AreaModel
.
areaCode
==
params
.
get
(
'areaCode'
))
.
first
()
logger
.
warn
(
result
)
if
result
and
result
.
is_delete
:
result
.
is_delete
=
False
result
.
update_by
=
jwt
[
'id'
]
result
.
update_by
=
jwt
.
get
(
"id"
,
""
)
result
.
update_date
=
datetime
.
now
()
db
.
session
.
commit
()
return
response_result
(
ResponseCode
.
OK
)
return
(
True
,
None
)
elif
result
and
result
.
is_delete
==
False
:
return
response_result
(
ResponseCode
.
EXISTS_ERROR
)
return
(
False
,
"area code exists"
)
result
=
AreaModel
(
**
params
)
db
.
session
.
add
(
result
)
db
.
session
.
commit
()
return
response_result
(
ResponseCode
.
OK
)
return
(
True
,
None
)
def
put
(
self
,
id
,
params
,
jwt
=
None
):
# handle business
...
...
tools/build_out/controllers/login.py
View file @
e3e9ca7a
...
...
@@ -12,7 +12,7 @@ class LoginResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
order_by
(
LoginModel
.
areaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
order_by
(
LoginModel
.
user
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
@@ -20,7 +20,7 @@ class LoginResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
order_by
(
LoginModel
.
areaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
LoginModel
.
query
.
filter
(
*
filters
)
.
order_by
(
LoginModel
.
user
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
tools/build_out/controllers/package.py
View file @
e3e9ca7a
...
...
@@ -12,7 +12,7 @@ class PackageResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
order_by
(
PackageModel
.
a
reaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
order_by
(
PackageModel
.
a
pp
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
@@ -20,7 +20,7 @@ class PackageResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
order_by
(
PackageModel
.
a
reaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
PackageModel
.
query
.
filter
(
*
filters
)
.
order_by
(
PackageModel
.
a
pp
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
tools/build_out/controllers/user.py
View file @
e3e9ca7a
...
...
@@ -12,7 +12,7 @@ class UserResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
order_by
(
UserModel
.
a
reaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
order_by
(
UserModel
.
a
pp_name
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
@@ -20,7 +20,7 @@ class UserResource(object):
# handle business
logger
.
warn
(
params
)
filters
=
[]
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
order_by
(
UserModel
.
a
reaId
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
result
=
UserModel
.
query
.
filter
(
*
filters
)
.
order_by
(
UserModel
.
a
pp_name
)
.
paginate
(
params
.
get
(
'page'
,
1
),
params
.
get
(
'pageSize'
,
10
),
error_out
=
False
)
return
result
...
...
tools/build_out/models/__init__.py
View file @
e3e9ca7a
# -*- coding: utf-8 -*-
from
sqlalchemy
import
create_engine
from
sqlalchemy
import
Column
,
Integer
,
String
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declared_attr
,
declarative_base
class
BaseModelMixin
(
object
):
...
...
@@ -26,4 +27,32 @@ class MyMixin(object):
# example:
class
MyModel
(
MyMixin
,
BaseModel
):
name
=
Column
(
String
(
1000
))
__tablename__
=
'mymodel'
name
=
Column
(
String
(
20
))
fullname
=
Column
(
String
(
32
))
password
=
Column
(
String
(
32
))
# if __name__ == "__main__":
engine
=
create_engine
(
'sqlite:///test.db'
)
BaseModel
.
metadata
.
create_all
(
engine
,
checkfirst
=
True
)
Session
=
sessionmaker
(
bind
=
engine
)
session
=
Session
()
ed_user
=
MyModel
(
name
=
'ed'
,
fullname
=
'Ed Jones'
,
password
=
'edspassword'
)
session
.
add
(
ed_user
)
session
.
add_all
(
[
MyModel
(
name
=
'wendy'
,
fullname
=
'Wendy Williams'
,
password
=
'foobar'
),
MyModel
(
name
=
'mary'
,
fullname
=
'Mary Contrary'
,
password
=
'xxg527'
),
MyModel
(
name
=
'fred'
,
fullname
=
'Fred Flinstone'
,
password
=
'blah'
)
]
)
session
.
commit
()
our_user
=
session
.
query
(
MyModel
)
.
filter_by
(
name
=
'ed'
)
.
first
()
print
(
our_user
)
\ No newline at end of file
tools/build_out/models/app.py
View file @
e3e9ca7a
...
...
@@ -7,17 +7,17 @@ from marshmallow import Schema, fields, INCLUDE, EXCLUDE
class
AppModel
(
PrimaryModel
):
__tablename__
=
'evm_app'
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
)
app_icon
=
db
.
Column
(
db
.
String
(
200
))
app_version
=
db
.
Column
(
db
.
String
(
20
))
category
=
db
.
Column
(
db
.
Integer
)
category_2th
=
db
.
Column
(
db
.
Integer
)
developer
=
db
.
Column
(
db
.
Integer
)
download_url
=
db
.
Column
(
db
.
String
(
20
))
app_file_size
=
db
.
Column
(
db
.
Integer
)
app_screen_size
=
db
.
Column
(
db
.
Integer
)
app_arch
=
db
.
Column
(
db
.
String
(
20
))
app_review
=
db
.
Column
(
db
.
String
(
100
))
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
False
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
developer
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
download_url
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
False
)
app_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_screen_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_arch
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
False
)
app_review
=
db
.
Column
(
db
.
String
(
100
)
,
nullable
=
False
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
...
...
tools/build_out/models/area.py
View file @
e3e9ca7a
...
...
@@ -7,13 +7,13 @@ from marshmallow import Schema, fields, INCLUDE, EXCLUDE
class
AreaModel
(
PrimaryModel
):
__tablename__
=
'evm_area'
areaCode
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
)
areaName
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
)
level
=
db
.
Column
(
db
.
Integer
,
default
=
1
)
cityCode
=
db
.
Column
(
db
.
Integer
)
center
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
)
parentId
=
db
.
Column
(
db
.
String
(
20
))
hasChildren
=
db
.
Column
(
db
.
Boolean
)
areaCode
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
)
areaName
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
)
level
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
,
default
=
1
)
cityCode
=
db
.
Column
(
db
.
Integer
,
nullable
=
True
)
center
=
db
.
Column
(
db
.
String
(
20
),
index
=
True
,
nullable
=
False
)
parentId
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
True
)
hasChildren
=
db
.
Column
(
db
.
Boolean
,
nullable
=
True
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
...
...
@@ -52,6 +52,8 @@ class PostAreaSchema(ma.SQLAlchemySchema):
areaCode
=
ma
.
auto_field
()
areaName
=
ma
.
auto_field
()
level
=
ma
.
auto_field
()
parentId
=
ma
.
auto_field
()
hasChildren
=
ma
.
auto_field
()
cityCode
=
ma
.
auto_field
()
center
=
ma
.
auto_field
()
...
...
tools/build_out/models/base.py
View file @
e3e9ca7a
...
...
@@ -4,6 +4,9 @@ import uuid
from
datetime
import
datetime
from
application.app
import
db
def
generate_uuid
():
return
uuid
.
uuid1
()
.
hex
class
BaseModel
(
db
.
Model
):
# Flask-SQLAlchemy创建table时,如何声明基类(这个类不会创建表,可以被继承)
# 方法就是把__abstract__这个属性设置为True,这个类为基类,不会被创建为表!
...
...
@@ -18,7 +21,7 @@ class BaseModel(db.Model):
class
PrimaryModel
(
BaseModel
):
__abstract__
=
True
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
uuid
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
True
,
default
=
uuid
.
uuid1
)
uuid
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
False
,
default
=
generate_uuid
)
class
AutoBaseModel
(
BaseModel
):
__abstract__
=
True
...
...
@@ -27,7 +30,7 @@ class AutoBaseModel(BaseModel):
class
UuidBaseModel
(
BaseModel
):
__abstract__
=
True
id
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
True
,
default
=
uuid
.
uuid1
)
id
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
True
,
default
=
generate_uuid
)
sort
=
db
.
Column
(
db
.
Integer
,
default
=
0
)
class
SortBaseModel
(
BaseModel
):
...
...
tools/build_out/models/login.py
View file @
e3e9ca7a
...
...
@@ -7,12 +7,12 @@ from marshmallow import Schema, fields, INCLUDE, EXCLUDE
class
LoginModel
(
PrimaryModel
):
__tablename__
=
'evm_login'
user
=
db
.
Column
(
db
.
Integer
)
login_at
=
db
.
Column
(
db
.
String
(
200
))
user_agent
=
db
.
Column
(
db
.
String
(
200
))
ip
=
db
.
Column
(
db
.
String
(
128
))
geo_location
=
db
.
Column
(
db
.
String
(
200
))
operator
=
db
.
Column
(
db
.
String
(
50
))
user
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
login_at
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
user_agent
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
ip
=
db
.
Column
(
db
.
String
(
128
)
,
nullable
=
False
)
geo_location
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
operator
=
db
.
Column
(
db
.
String
(
50
)
,
nullable
=
False
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
...
...
tools/build_out/models/package.py
View file @
e3e9ca7a
...
...
@@ -7,16 +7,16 @@ from marshmallow import Schema, fields, INCLUDE, EXCLUDE
class
PackageModel
(
PrimaryModel
):
__tablename__
=
'evm_package'
app
=
db
.
Column
(
db
.
Integer
)
app_version
=
db
.
Column
(
db
.
String
(
200
))
package_info
=
db
.
Column
(
db
.
String
(
20
))
file_path
=
db
.
Column
(
db
.
String
(
200
))
source
=
db
.
Column
(
db
.
Integer
)
user_agent
=
db
.
Column
(
db
.
String
(
200
))
download_url
=
db
.
Column
(
db
.
String
(
200
))
ip
=
db
.
Column
(
db
.
String
(
128
))
geo_location
=
db
.
Column
(
db
.
String
(
200
))
operator
=
db
.
Column
(
db
.
String
(
50
))
app
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
package_info
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
False
)
file_path
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
source
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
user_agent
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
download_url
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
ip
=
db
.
Column
(
db
.
String
(
128
)
,
nullable
=
False
)
geo_location
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
operator
=
db
.
Column
(
db
.
String
(
50
)
,
nullable
=
False
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
...
...
tools/build_out/models/user.py
View file @
e3e9ca7a
...
...
@@ -7,17 +7,17 @@ from marshmallow import Schema, fields, INCLUDE, EXCLUDE
class
UserModel
(
PrimaryModel
):
__tablename__
=
'evm_user'
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
)
app_icon
=
db
.
Column
(
db
.
String
(
200
))
app_version
=
db
.
Column
(
db
.
String
(
20
))
category
=
db
.
Column
(
db
.
Integer
)
category_2th
=
db
.
Column
(
db
.
Integer
)
developer
=
db
.
Column
(
db
.
Integer
)
download_url
=
db
.
Column
(
db
.
String
(
20
))
app_file_size
=
db
.
Column
(
db
.
Integer
)
app_screen_size
=
db
.
Column
(
db
.
Integer
)
app_arch
=
db
.
Column
(
db
.
String
(
20
))
app_review
=
db
.
Column
(
db
.
String
(
100
))
app_name
=
db
.
Column
(
db
.
String
(
70
),
index
=
True
,
nullable
=
False
)
app_icon
=
db
.
Column
(
db
.
String
(
200
)
,
nullable
=
False
)
app_version
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
False
)
category
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
category_2th
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
developer
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
download_url
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
False
)
app_file_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_screen_size
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
app_arch
=
db
.
Column
(
db
.
String
(
20
)
,
nullable
=
False
)
app_review
=
db
.
Column
(
db
.
String
(
100
)
,
nullable
=
False
)
# __table_args__ = (
# db.Index('idx_xxx', 'xxx', mysql_using='btree'),
...
...
tools/build_out/tests/test_sqlalchemy_sqlite.py
0 → 100644
View file @
e3e9ca7a
import
sqlalchemy
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
Column
,
Integer
,
String
Base
=
declarative_base
()
print
(
sqlalchemy
.
__version__
)
# where <path> is relative:
engine
=
create_engine
(
'sqlite:///test.db'
)
# Unix/Mac - 4 initial slashes in total
# engine = create_engine('sqlite:////absolute/path/to/foo.db')
# # Windows
# engine = create_engine('sqlite:///C:\\path\\to\\foo.db')
# # Windows alternative using raw string
# engine = create_engine(r'sqlite:///C:\path\to\foo.db')
# 定义映射类User,其继承上一步创建的Base
class
User
(
Base
):
# 指定本类映射到users表
__tablename__
=
'users'
# 如果有多个类指向同一张表,那么在后边的类需要把extend_existing设为True,表示在已有列基础上进行扩展
# 或者换句话说,sqlalchemy允许类是表的字集
# __table_args__ = {'extend_existing': True}
# 如果表在同一个数据库服务(datebase)的不同数据库中(schema),可使用schema参数进一步指定数据库
# __table_args__ = {'schema': 'test_database'}
# 各变量名一定要与表的各字段名一样,因为相同的名字是他们之间的唯一关联关系
# 从语法上说,各变量类型和表的类型可以不完全一致,如表字段是String(64),但我就定义成String(32)
# 但为了避免造成不必要的错误,变量的类型和其对应的表的字段的类型还是要相一致
# sqlalchemy强制要求必须要有主键字段不然会报错,如果要映射一张已存在且没有主键的表,那么可行的做法是将所有字段都设为primary_key=True
# 不要看随便将一个非主键字段设为primary_key,然后似乎就没报错就能使用了,sqlalchemy在接收到查询结果后还会自己根据主键进行一次去重
# 指定id映射到id字段; id字段为整型,为主键,自动增长(其实整型主键默认就自动增长)
id
=
Column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
# 指定name映射到name字段; name字段为字符串类形,
name
=
Column
(
String
(
20
))
fullname
=
Column
(
String
(
32
))
password
=
Column
(
String
(
32
))
# __repr__方法用于输出该类的对象被print()时输出的字符串,如果不想写可以不写
def
__repr__
(
self
):
return
"<User(name='
%
s', fullname='
%
s', password='
%
s')>"
%
(
self
.
name
,
self
.
fullname
,
self
.
password
)
def
get_dynamic_table_name_class
(
table_name
):
# 定义一个内部类
class
TestModel
(
Base
):
# 给表名赋值
__tablename__
=
table_name
__table_args__
=
{
'extend_existing'
:
True
}
username
=
Column
(
String
(
32
),
primary_key
=
True
)
password
=
Column
(
String
(
32
))
# 把动态设置表名的类返回去
return
TestModel
# 查看映射对应的表
print
(
User
.
__table__
)
# 创建数据表。一方面通过engine来连接数据库,另一方面根据哪些类继承了Base来决定创建哪些表
# checkfirst=True,表示创建表前先检查该表是否存在,如同名表已存在则不再创建。其实默认就是True
Base
.
metadata
.
create_all
(
engine
,
checkfirst
=
True
)
# 上边的写法会在engine对应的数据库中创建所有继承Base的类对应的表,但很多时候很多只是用来则试的或是其他库的
# 此时可以通过tables参数指定方式,指示仅创建哪些表
# Base.metadata.create_all(engine,tables=[Base.metadata.tables['users']],checkfirst=True)
# 在项目中由于model经常在别的文件定义,没主动加载时上边的写法可能写导致报错,可使用下边这种更明确的写法
# User.__table__.create(engine, checkfirst=True)
# 另外我们说这一步的作用是创建表,当我们已经确定表已经在数据库中存在时,我完可以跳过这一步
# 针对已存放有关键数据的表,或大家共用的表,直接不写这创建代码更让人心里踏实
# engine是2.2中创建的连接
Session
=
sessionmaker
(
bind
=
engine
)
# 创建Session类实例
session
=
Session
()
if
__name__
==
"__main__"
:
# 创建User类实例
ed_user
=
User
(
name
=
'ed'
,
fullname
=
'Ed Jones'
,
password
=
'edspassword'
)
# 将该实例插入到users表
session
.
add
(
ed_user
)
# 一次插入多条记录形式
session
.
add_all
(
[
User
(
name
=
'wendy'
,
fullname
=
'Wendy Williams'
,
password
=
'foobar'
),
User
(
name
=
'mary'
,
fullname
=
'Mary Contrary'
,
password
=
'xxg527'
),
User
(
name
=
'fred'
,
fullname
=
'Fred Flinstone'
,
password
=
'blah'
)
]
)
# 当前更改只是在session中,需要使用commit确认更改才会写入数据库
session
.
commit
()
our_user
=
session
.
query
(
User
)
.
filter_by
(
name
=
'ed'
)
.
first
()
print
(
our_user
)
\ No newline at end of file
tools/build_out/views/area.py
View file @
e3e9ca7a
...
...
@@ -23,26 +23,33 @@ class AreaResourceList(Resource):
json_payload
=
request
.
json
logger
.
warn
(
json_payload
)
data
=
getListAreaSchema
.
load
(
json_payload
)
logger
.
warn
(
"######################"
)
result
=
signalManager
.
actionGetArea
.
emit
(
data
)
logger
.
warn
(
"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
)
logger
.
warn
(
result
)
json_dumps
=
result
#
json_dumps = result
# json_dumps = getListAreaSchema.dump(result)
return
json_dumps
,
200
# logger.warn(json_dumps)
return
response_result
(
ResponseCode
.
OK
,
data
=
result
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
return
response_result
(
ResponseCode
.
SERVER
_ERROR
)
@
jwt_required
#
@jwt_required
def
post
(
self
):
try
:
json_payload
=
request
.
json
data
=
postAreaSchema
.
load
(
json_payload
)
logger
.
warn
(
data
)
result
=
signalManager
.
actionPostArea
.
emit
(
data
)
json_dumps
=
postAreaSchema
.
dump
(
result
)
return
jsonify
(
json_dumps
),
200
if
result
[
0
]
==
False
:
return
response_result
(
ResponseCode
.
REQUEST_ERROR
,
msg
=
result
[
1
])
logger
.
warn
(
result
)
# json_dumps = postAreaSchema.dump(result)
return
response_result
(
ResponseCode
.
OK
)
except
Exception
as
e
:
current_app
.
logger
.
error
(
e
)
return
response_result
(
ResponseCode
.
DB
_ERROR
)
return
response_result
(
ResponseCode
.
SERVER
_ERROR
)
class
AreaResource
(
Resource
):
...
...
tools/build_out/webcreator/log.py
View file @
e3e9ca7a
...
...
@@ -19,7 +19,7 @@ fh.setLevel(logging.DEBUG)
ch
=
logging
.
StreamHandler
()
ch
.
setLevel
(
logging
.
WARNING
)
formatter
=
logging
.
Formatter
(
'[
%(asctime)
s][
%(levelname)7
s]
[in
%(pathname)
s ->
%(funcName)
s line:
%(lineno)
s]
%(message)
s'
)
formatter
=
logging
.
Formatter
(
'[
%(asctime)
s][
%(levelname)7
s][in
%(pathname)
s ->
%(funcName)
s line:
%(lineno)
s]
%(message)
s'
)
fh
.
setFormatter
(
formatter
)
ch
.
setFormatter
(
formatter
)
...
...
tools/config.json
View file @
e3e9ca7a
...
...
@@ -3,9 +3,10 @@
"name"
:
"evm-store"
,
"host"
:
"127.0.0.1"
,
"port"
:
1000
,
"jwtSecret"
:
""
,
"jwtSecret"
:
"
6UdxRgs2hvWpTLmj027d5vt7dXXQX
"
,
"tablePrefix"
:
"evm_"
,
"logLevel"
:
"debug"
,
"logLevel"
:
"DEBUG"
,
"database"
:
"sqlite"
,
"mysql"
:
{
"host"
:
"127.0.0.1"
,
"port"
:
3306
,
...
...
@@ -89,7 +90,7 @@
"default"
:
""
,
"length"
:
20
,
"index"
:
false
,
"required"
:
tru
e
,
"required"
:
fals
e
,
"toJson"
:
true
},
{
...
...
@@ -127,6 +128,20 @@
"default"
:
1
,
"required"
:
false
},
{
"name"
:
"parentId"
,
"dataType"
:
"String"
,
"location"
:
"args"
,
"default"
:
""
,
"required"
:
false
},
{
"name"
:
"hasChildren"
,
"dataType"
:
"Boolean"
,
"location"
:
"args"
,
"default"
:
false
,
"required"
:
false
},
{
"name"
:
"cityCode"
,
"detaType"
:
"String"
,
...
...
tools/gen_code.py
View file @
e3e9ca7a
...
...
@@ -87,6 +87,11 @@ def handleModel(config, application):
target_file
=
os
.
sep
.
join
([
"models"
,
"{}.py"
.
format
(
config
.
get
(
"name"
))])
handleRender
(
config
,
'model.tpl'
,
target_file
,
fields
=
fields
,
extend
=
extend
,
application
=
application
)
# 多次复制时,会报文件已存在错误,因此要先删除
target_file
=
os
.
sep
.
join
([
"models"
,
"base.py"
])
if
os
.
path
.
exists
(
target_file
):
os
.
remove
(
target_file
)
handleRender
(
config
,
'base.tpl'
,
target_file
,
application
=
application
)
def
handleView
(
config
):
target_file
=
os
.
sep
.
join
([
"views"
,
"{}.py"
.
format
(
config
.
get
(
"name"
))])
...
...
@@ -119,6 +124,8 @@ def handleRender(result, tpl, target_file, **kwargs):
if
os
.
path
.
exists
(
target_file
)
and
os
.
stat
(
target_file
)
.
st_size
>
0
:
n
,
e
=
os
.
path
.
splitext
(
target_file
)
tmp_file
=
"{}.{}{}"
.
format
(
n
,
time
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
,
time
.
localtime
()),
e
)
if
os
.
path
.
exists
(
tmp_file
):
os
.
remove
(
tmp_file
)
os
.
rename
(
target_file
,
tmp_file
)
with
open
(
target_file
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
...
...
tools/resources/application/app.py
View file @
e3e9ca7a
...
...
@@ -98,7 +98,10 @@ def create_app(config):
# 自定义abort 400 响应数据格式
flask_restful
.
abort
=
_custom_abort
# 数据库初始化
# db.app = app
db
.
init_app
(
app
)
# 创建表
db
.
create_all
()
# 注册蓝图
from
views
import
api_v1
app
.
register_blueprint
(
api_v1
,
url_prefix
=
'/api/v1'
)
...
...
tools/resources/application/config.py
View file @
e3e9ca7a
...
...
@@ -32,13 +32,15 @@ class ProductionConfig(object):
MYSQL_PORT
=
3306
MYSQL_USER
=
'debian-sys-maint'
MYSQL_PWD
=
'XMigC2B2uugnv18y'
SQLALCHEMY_BINDS
=
"sqlite:////test.db"
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
SQLALCHEMY_BINDS
=
{
'app-store'
:
'sqlite:///../test.db'
}
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
def
__init__
(
self
):
super
()
.
__init__
()
self
.
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
self
.
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
class
DevelopConfig
(
object
):
...
...
@@ -66,15 +68,17 @@ class DevelopConfig(object):
MYSQL_PORT
=
3306
MYSQL_USER
=
'debian-sys-maint'
MYSQL_PWD
=
'XMigC2B2uugnv18y'
SQLALCHEMY_BINDS
=
"sqlite:////test.db"
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
SQLALCHEMY_BINDS
=
{
'app-store'
:
'sqlite:///../test.db'
}
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
SQLALCHEMY_TRACK_MODIFICATIONS
=
True
SQLALCHEMY_ECHO
=
False
def
__init__
(
self
):
super
()
.
__init__
()
self
.
SQLALCHEMY_DATABASE_URI
=
"sqlite:////test.db"
self
.
SQLALCHEMY_DATABASE_URI
=
'sqlite:///../test.db'
if
MODE
==
'production'
:
config
=
ProductionConfig
()
...
...
tools/resources/models/__init__.py
View file @
e3e9ca7a
# -*- coding: utf-8 -*-
from
sqlalchemy
import
create_engine
from
sqlalchemy
import
Column
,
Integer
,
String
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declared_attr
,
declarative_base
class
BaseModelMixin
(
object
):
...
...
@@ -26,4 +27,32 @@ class MyMixin(object):
# example:
class
MyModel
(
MyMixin
,
BaseModel
):
name
=
Column
(
String
(
1000
))
__tablename__
=
'mymodel'
name
=
Column
(
String
(
20
))
fullname
=
Column
(
String
(
32
))
password
=
Column
(
String
(
32
))
# if __name__ == "__main__":
engine
=
create_engine
(
'sqlite:///test.db'
)
BaseModel
.
metadata
.
create_all
(
engine
,
checkfirst
=
True
)
Session
=
sessionmaker
(
bind
=
engine
)
session
=
Session
()
ed_user
=
MyModel
(
name
=
'ed'
,
fullname
=
'Ed Jones'
,
password
=
'edspassword'
)
session
.
add
(
ed_user
)
session
.
add_all
(
[
MyModel
(
name
=
'wendy'
,
fullname
=
'Wendy Williams'
,
password
=
'foobar'
),
MyModel
(
name
=
'mary'
,
fullname
=
'Mary Contrary'
,
password
=
'xxg527'
),
MyModel
(
name
=
'fred'
,
fullname
=
'Fred Flinstone'
,
password
=
'blah'
)
]
)
session
.
commit
()
our_user
=
session
.
query
(
MyModel
)
.
filter_by
(
name
=
'ed'
)
.
first
()
print
(
our_user
)
\ No newline at end of file
tools/resources/tests/test_sqlalchemy_sqlite.py
0 → 100644
View file @
e3e9ca7a
import
sqlalchemy
from
sqlalchemy
import
create_engine
from
sqlalchemy.orm
import
sessionmaker
from
sqlalchemy.ext.declarative
import
declarative_base
from
sqlalchemy
import
Column
,
Integer
,
String
Base
=
declarative_base
()
print
(
sqlalchemy
.
__version__
)
# where <path> is relative:
engine
=
create_engine
(
'sqlite:///test.db'
)
# Unix/Mac - 4 initial slashes in total
# engine = create_engine('sqlite:////absolute/path/to/foo.db')
# # Windows
# engine = create_engine('sqlite:///C:\\path\\to\\foo.db')
# # Windows alternative using raw string
# engine = create_engine(r'sqlite:///C:\path\to\foo.db')
# 定义映射类User,其继承上一步创建的Base
class
User
(
Base
):
# 指定本类映射到users表
__tablename__
=
'users'
# 如果有多个类指向同一张表,那么在后边的类需要把extend_existing设为True,表示在已有列基础上进行扩展
# 或者换句话说,sqlalchemy允许类是表的字集
# __table_args__ = {'extend_existing': True}
# 如果表在同一个数据库服务(datebase)的不同数据库中(schema),可使用schema参数进一步指定数据库
# __table_args__ = {'schema': 'test_database'}
# 各变量名一定要与表的各字段名一样,因为相同的名字是他们之间的唯一关联关系
# 从语法上说,各变量类型和表的类型可以不完全一致,如表字段是String(64),但我就定义成String(32)
# 但为了避免造成不必要的错误,变量的类型和其对应的表的字段的类型还是要相一致
# sqlalchemy强制要求必须要有主键字段不然会报错,如果要映射一张已存在且没有主键的表,那么可行的做法是将所有字段都设为primary_key=True
# 不要看随便将一个非主键字段设为primary_key,然后似乎就没报错就能使用了,sqlalchemy在接收到查询结果后还会自己根据主键进行一次去重
# 指定id映射到id字段; id字段为整型,为主键,自动增长(其实整型主键默认就自动增长)
id
=
Column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
# 指定name映射到name字段; name字段为字符串类形,
name
=
Column
(
String
(
20
))
fullname
=
Column
(
String
(
32
))
password
=
Column
(
String
(
32
))
# __repr__方法用于输出该类的对象被print()时输出的字符串,如果不想写可以不写
def
__repr__
(
self
):
return
"<User(name='
%
s', fullname='
%
s', password='
%
s')>"
%
(
self
.
name
,
self
.
fullname
,
self
.
password
)
def
get_dynamic_table_name_class
(
table_name
):
# 定义一个内部类
class
TestModel
(
Base
):
# 给表名赋值
__tablename__
=
table_name
__table_args__
=
{
'extend_existing'
:
True
}
username
=
Column
(
String
(
32
),
primary_key
=
True
)
password
=
Column
(
String
(
32
))
# 把动态设置表名的类返回去
return
TestModel
# 查看映射对应的表
print
(
User
.
__table__
)
# 创建数据表。一方面通过engine来连接数据库,另一方面根据哪些类继承了Base来决定创建哪些表
# checkfirst=True,表示创建表前先检查该表是否存在,如同名表已存在则不再创建。其实默认就是True
Base
.
metadata
.
create_all
(
engine
,
checkfirst
=
True
)
# 上边的写法会在engine对应的数据库中创建所有继承Base的类对应的表,但很多时候很多只是用来则试的或是其他库的
# 此时可以通过tables参数指定方式,指示仅创建哪些表
# Base.metadata.create_all(engine,tables=[Base.metadata.tables['users']],checkfirst=True)
# 在项目中由于model经常在别的文件定义,没主动加载时上边的写法可能写导致报错,可使用下边这种更明确的写法
# User.__table__.create(engine, checkfirst=True)
# 另外我们说这一步的作用是创建表,当我们已经确定表已经在数据库中存在时,我完可以跳过这一步
# 针对已存放有关键数据的表,或大家共用的表,直接不写这创建代码更让人心里踏实
# engine是2.2中创建的连接
Session
=
sessionmaker
(
bind
=
engine
)
# 创建Session类实例
session
=
Session
()
if
__name__
==
"__main__"
:
# 创建User类实例
ed_user
=
User
(
name
=
'ed'
,
fullname
=
'Ed Jones'
,
password
=
'edspassword'
)
# 将该实例插入到users表
session
.
add
(
ed_user
)
# 一次插入多条记录形式
session
.
add_all
(
[
User
(
name
=
'wendy'
,
fullname
=
'Wendy Williams'
,
password
=
'foobar'
),
User
(
name
=
'mary'
,
fullname
=
'Mary Contrary'
,
password
=
'xxg527'
),
User
(
name
=
'fred'
,
fullname
=
'Fred Flinstone'
,
password
=
'blah'
)
]
)
# 当前更改只是在session中,需要使用commit确认更改才会写入数据库
session
.
commit
()
our_user
=
session
.
query
(
User
)
.
filter_by
(
name
=
'ed'
)
.
first
()
print
(
our_user
)
\ No newline at end of file
tools/resources/webcreator/log.py
View file @
e3e9ca7a
...
...
@@ -19,7 +19,7 @@ fh.setLevel(logging.DEBUG)
ch
=
logging
.
StreamHandler
()
ch
.
setLevel
(
logging
.
WARNING
)
formatter
=
logging
.
Formatter
(
'[
%(asctime)
s][
%(levelname)7
s]
[in
%(pathname)
s ->
%(funcName)
s line:
%(lineno)
s]
%(message)
s'
)
formatter
=
logging
.
Formatter
(
'[
%(asctime)
s][
%(levelname)7
s][in
%(pathname)
s ->
%(funcName)
s line:
%(lineno)
s]
%(message)
s'
)
fh
.
setFormatter
(
formatter
)
ch
.
setFormatter
(
formatter
)
...
...
tools/
resources/models/base.py
→
tools/
templates/base.tpl
View file @
e3e9ca7a
...
...
@@ -4,6 +4,9 @@ import uuid
from datetime import datetime
from application.app import db
def generate_uuid():
return uuid.uuid1().hex
class BaseModel(db.Model):
# Flask-SQLAlchemy创建table时,如何声明基类(这个类不会创建表,可以被继承)
# 方法就是把__abstract__这个属性设置为True,这个类为基类,不会被创建为表!
...
...
@@ -17,17 +20,17 @@ class BaseModel(db.Model):
class PrimaryModel(BaseModel):
__abstract__ = True
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
uuid
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
True
,
default
=
uuid
.
uuid1
)
id = db.Column(db.Integer, primary_key=True
{% if application.get("database") == "mysql" or application.get("database") == "sqlite" %}, autoincrement=True{% else %}, autoincrement=False{% endif %}
)
uuid = db.Column(db.String(64), primary_key=
False, default=generate_uuid
)
class AutoBaseModel(BaseModel):
__abstract__ = True
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
id = db.Column(db.Integer, primary_key=True
{% if application.get("database") == "mysql" or application.get("database") == "sqlite" %}, autoincrement=True{% else %}, autoincrement=False{% endif %}
)
sort = db.Column(db.Integer, default=0)
class UuidBaseModel(BaseModel):
__abstract__ = True
id
=
db
.
Column
(
db
.
String
(
64
),
primary_key
=
True
,
default
=
uuid
.
uuid1
)
id = db.Column(db.String(64), primary_key=True, default=
generate_uuid
)
sort = db.Column(db.Integer, default=0)
class SortBaseModel(BaseModel):
...
...
tools/templates/controller.tpl
View file @
e3e9ca7a
...
...
@@ -12,7 +12,7 @@ class {{ config['name'] | letterUpper }}Resource(object):
# handle business
logger.warn(params)
filters = []
result = {{ config['name'] | letterUpper }}Model.query.filter(*filters).order_by({{ config['name'] | letterUpper }}Model.
areaId
).paginate(params.get('page', 1), params.get('pageSize', 10), error_out=False)
result = {{ config['name'] | letterUpper }}Model.query.filter(*filters).order_by({{ config['name'] | letterUpper }}Model.
{{ config["model"]["fields"][0]["name"] }}
).paginate(params.get('page', 1), params.get('pageSize', 10), error_out=False)
return result
...
...
@@ -20,7 +20,7 @@ class {{ config['name'] | letterUpper }}Resource(object):
# handle business
logger.warn(params)
filters = []
result = {{ config['name'] | letterUpper }}Model.query.filter(*filters).order_by({{ config['name'] | letterUpper }}Model.
areaId
).paginate(params.get('page', 1), params.get('pageSize', 10), error_out=False)
result = {{ config['name'] | letterUpper }}Model.query.filter(*filters).order_by({{ config['name'] | letterUpper }}Model.
{{ config["model"]["fields"][0]["name"] }}
).paginate(params.get('page', 1), params.get('pageSize', 10), error_out=False)
return result
...
...
@@ -32,14 +32,14 @@ class {{ config['name'] | letterUpper }}Resource(object):
result.update_by = jwt['id']
result.update_date = datetime.now()
db.session.commit()
return
response_result(ResponseCode.OK
)
return
(True, None
)
elif result and result.is_delete == False:
return
response_result(ResponseCode.EXISTS_ERROR
)
return
(False, "exists"
)
result = {{ config['name'] | letterUpper }}Model(**params)
db.session.add(result)
db.session.commit()
return
response_result(ResponseCode.OK
)
return
(True, None
)
def put(self, id, params, jwt=None):
# handle business
...
...
tools/templates/model.tpl
View file @
e3e9ca7a
...
...
@@ -10,11 +10,11 @@ class {{ config['name'] | letterUpper }}Model(PrimaryModel):
__tablename__ = '{{ application["tablePrefix"] }}{{ config['name'] }}'
{% for value in config['model']['fields'] %}
{%- if value.get('primaryKey', None) %}
{{ value.get('name') }} = db.Column(db.{{ value.get('dataType') }}, primary_key = True
, {% if value.get('autoIncrement') %}autoincrement = True{% endif %}
)
{{ value.get('name') }} = db.Column(db.{{ value.get('dataType') }}, primary_key = True)
{%- elif value.get('dataType') == "Int" or value.get('dataType') == "Integer" %}
{{ value.get('name') }} = db.Column(db.{{ value.get('dataType') }}{% if value.get("length", None) %}{% endif %}{% if value.get("index", False) %}, index = True{% endif %}{% if value.get("default", None) %}, default = {
{
value
.
get
(
"default"
)
}
}{% endif %})
{{ value.get('name') }} = db.Column(db.{{ value.get('dataType') }}{% if value.get("length", None) %}{% endif %}{% if value.get("index", False) %}, index = True{% endif %}{% if value.get("
required", False) %}, nullable = False{% else %}, nullable = True{% endif %}{% if value.get("
default", None) %}, default = {
{
value
.
get
(
"default"
)
}
}{% endif %})
{%- else %}
{{ value.get('name') }} = db.Column(db.{{ value.get('dataType') }}{% if value.get("length", None) %}({
{
value
.
get
(
"length"
)
}
}){% endif %}{% if value.get("index", False) %}, index = True{% endif %}{% if value.get("default", None) %}, default = {
{
value
.
get
(
"default"
)
}
}{% endif %})
{{ value.get('name') }} = db.Column(db.{{ value.get('dataType') }}{% if value.get("length", None) %}({
{
value
.
get
(
"length"
)
}
}){% endif %}{% if value.get("index", False) %}, index = True{% endif %}{% if value.get("
required", False) %}, nullable = False{% else %}, nullable = True{% endif %}{% if value.get("
default", None) %}, default = {
{
value
.
get
(
"default"
)
}
}{% endif %})
{%- endif %}
{%- endfor %}
...
...
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