上药三品,神与气精

曾因酒醉鞭名马 生怕情多累美人


  • 首页

  • 关于

  • 分类

  • 标签

  • 归档

  • 搜索

pg-update-tz

发表于 2019-02-14 | 阅读次数:
字数统计: 101 | 阅读时长 ≈ 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
例如要将默认的PRC修改为UTC
可以从几个方面来修改
1. 全局参数
postgresql.conf
timezone='UTC'

2. 数据库级配置
alter database dbname set timezone='UTC';

pipeline=# select * from pg_db_role_setting ;
setdatabase | setrole | setconfig
-------------+---------+--------------------------------------
14930 | 0 | {TimeZone=UTC}

3. 用户级配置
alter role rolname set timezone='UTC';
或者
alter role all set timezone='UTC';

pipeline=# select * from pg_db_role_setting ;
setdatabase | setrole | setconfig
-------------+---------+--------------------------------------
14930 | 0 | {TimeZone=UTC}
0 | 0 | {TimeZone=UTC}

2019-go-05

发表于 2019-02-13 | 分类于 golang | 阅读次数:
字数统计: 703 | 阅读时长 ≈ 2

目前而言 主力语言还是python

但是可能对未来十年的预期 是Golang

编译成单一的二进制

  Golang 是编译型语言并且 Googe 的开发者花了很大的功夫在上面。它使用静态链接实际上是基于操作系统类型和环境组合所有的依赖库文件和模块到一个单一的二进制文件中,这也意味着如果你想要编译你的后端应用到你的 Linux 操作系统和 X86 架构的 CPU 中,你只要下载编译好的二进制应用到服务器,然后可以后端应用可以工作了,这是不需要任何的依赖文件的。

静态类型系统

Python 是很棒的并且有趣的语言但是有些时候你会看到一些不寻常的异常因为当你尝试将变量作为一个整型变量的时候结果它是一个字符串类型.

1
2
3
# Django will crash process because of this 
def some_view(request):
  user_id = request.POST.get('id', 0)

Go 在编译的时候告诉你这是一个编译器错误,这就是在愚蠢的问题上赢得时间的地方。

优化

Go 语言由于自己的多线程模块和 CPU 可伸缩性获得了较好的性能。无论什么时候我们需要执行一些内部的请求,我们可以使用 Goroutine 来分别执行,这个比 Python 中的 Threads 在资源开销上要少上十多倍。由于这些内置的语言特性,我们可以节省大量的资源(内存和 CPU )。

不再需要web框架

对于编程语言这是一件十分酷的事情。Go 语言的创造者和社区内置了很多原生的被核心语言支持的工具,在大多数情况下你都不再需要任何第三方类库。比如它有内置的 http、json、html 模板,你甚至可以不用费心去 Github 上寻找第三方类库就可以构建十分复杂的 API 服务。

  当然,Go 也有很多类库和框架用来构建 web 项目,但是我会建议你不使用第三方类库来构建你的 web 项目或者 API 服务,因为在大多数情况下使用原生包会使你的生活更加轻松。

更好的 IDE 支持和调试???

  IDE 支持是当你尝试更改编程语言时最重要的考虑因素之一。友好的 IDE 平均可以节省你80%的编程时间。 Go Plugin For JetBrains IDEA ,同样提供了其他支持,比如 (Webstorm、PHPStorm 等等…)。这个插件提供了任何你在项目开发中需要的服务,强大的 JetBrains IDEA ,可以让你的开发如虎添翼。

2019-go-04

发表于 2019-02-13 | 分类于 golang | 阅读次数:
字数统计: 68 | 阅读时长 ≈ 1
  • 使用 Raw SQL 查询,无需使用 ORM 表定义
  • 多数据库,都可直接使用占位符号 ?,自动转换
  • 查询时的参数,支持使用 Model Struct 和 Slice, Array
1
2
3
4
insOrm:=orm.NewOrm()
var user models.Users
insOrm.Raw("SELECT name FROM Users WHERE id = ?", 1)..Exec()
this.Ctx.WriteString(user.Name)

2019-go-03

发表于 2019-02-13 | 分类于 golang | 阅读次数:
字数统计: 480 | 阅读时长 ≈ 2

基本使用

1
2
3
4
5
6
7
//创建Orm对象
o := orm.NewOrm()
// 获取 QuerySeter 对象,user 为表名
qs := o.QueryTable("user")
// 也可以直接使用对象作为表名
user := new(User)
qs = o.QueryTable(user) // 返回 QuerySeter

复杂一些的

1
2
3
4
5
6
7
8
9
10

qs.Filter("id", 1) // WHERE id = 1
qs.Filter("user__id",1) //where user.id =1
qs.Filter("id_in",10,20) //where age in(10,20)
qs.Filter("id__gte",18) //where id>=18
qs.Filter("id__gt",18) //where id>18
qs.Filter("id__,5) //where id<5
//gt 是greater缩写即大于
//get是 Greater or equal的缩写即大于等于
//lt 是less than 即小于

具体的例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

exact  ->  =
iexact -> like'
in -> in 
gt  ->  > 
gte-> >=
lt ->  <
lte ->  <=
contains ->  like BINARY '%xxx%' (区分大小写)
icontains -> like '%xxx%' (不区分大小写)
startswith -> LIKE BINARY 'xxx%' (区分大小写)
istartswith -> LIKE  'xxx%'
endswith -> LIKE BINARY '%xxx' (区分大小写)
iendswith -> LIKE  '%xxx'
isnull -> is not null
1
2
3
4
5
6
7
8
9
10

qs.Filter("id", 1) // WHERE id = 1
qs.Filter("user__id",1) //where user.id =1
qs.Filter("_id_in",10,20) //where age in(10,20)
qs.Filter("__id__gte",18) //where id>=18
qs.Filter("__id__gt",18) //where id>18
qs.Filter("__id__,5) //where id<5
//gt 是greater缩写即大于
//get是 Greater or equal的缩写即大于等于
//lt 是less than 即小于
1
2
3
4
5
6
7
8
9
10
11
12
var DefaultRelsDepth = 5 // 默认情况下直接调用 RelatedSel 将进行最大 5 层的关系查询

qs := o.QueryTable("post")

qs.RelatedSel()
// INNER JOIN user ... LEFT OUTER JOIN profile ...

qs.RelatedSel("user")
// INNER JOIN user ...
// 设置 expr 只对设置的字段进行关系查询

// 对设置 null 属性的 Field 将使用 LEFT OUTER JOIN
1
2
3
4
5
6

num, err := o.QueryTable("user").Filter("name", "slene").Update(orm.Params{
"name": "astaxie",
})
fmt.Printf("Affected Num: %s, %s", num, err)
// SET name = "astaixe" WHERE name = "slene"
1
2
3
var users []*User
num, err := o.QueryTable("user").Filter("name", "slene").All(&users)
fmt.Printf("Returned Rows Num: %s, %s", num, err)

受到limit限制 默认最大行数为1000

2019-go-02

发表于 2019-02-13 | 分类于 golang | 阅读次数:
字数统计: 417 | 阅读时长 ≈ 2

新增

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

func (this *InsertController) Post() {
/*
Name :="admin"
Pwd :="12346"
Sex :="男"
Age :=20
*/
Name :=this.GetString("Name")
Pwd :=this.GetString("Pwd")
Sex :=this.GetString("Sex")
Age,err:=this.GetInt("Age")
if err!=nil {
this.Ctx.WriteString("非法年龄字段")
return
}
user:=models.Users{Name:Name,Pwd:Pwd,Sex:Sex,Age:Age}
insOrm:=orm.NewOrm()
n,err:=insOrm.Insert(&user)
if err==nil&&n>0 {
this.Ctx.WriteString("数据插入成功")
}else{
this.Ctx.WriteString("数据插入失败")
}
}

读取read

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
func (this *QueryController)Get()  {

id,err:=this.GetInt("id")
if err!=nil {
this.Ctx.WriteString("id异常")
return
}
user:= models.Users{Id:id} //获取指定id的数据
orm:=orm.NewOrm()
err=orm.Read(&user) //读取数据
if err==nil {
this.Ctx.WriteString("id="+strconv.Itoa(user.Id)+"\nname="+user.Name+"\nsex="+user.Sex)
}else{
this.Ctx.WriteString("查询失败")
}

}

更新 update

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
func (this *UpdataController)Get()  {
Id,err:=this.GetInt("Id")
if err!=nil {
this.Ctx.WriteString("id异常")
return
}
Name :=this.GetString("Name")
Pwd :=this.GetString("Pwd")
Sex :=this.GetString("Sex")
Age,err:=this.GetInt("Age")
if err!=nil {
this.Ctx.WriteString("非法年龄字段")
return
}
user:= models.Users{Id:Id,Name:Name,Pwd:Pwd,Age:Age,Sex:Sex}
orm:=orm.NewOrm()
n,err:=orm.Update(&user)
if n>0&&err==nil{
this.Ctx.WriteString("更新成功")
}else{
this.Ctx.WriteString("更新失败")
}
}

删除 delete

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
func (this *DeleteController) Get()  {
id,err:=this.GetInt("id")
if err!=nil {
this.Ctx.WriteString("删除失败")
return
}
user:= models.Users{Id:id}
orm:=orm.NewOrm()
n,err:=orm.Delete(&user)
if n>0&&err==nil {
this.Ctx.WriteString("删除成功")
}else{
this.Ctx.WriteString("删除失败")
}

}
1…484950…109
John Cheung

John Cheung

improve your python skills

543 日志
33 分类
45 标签
RSS
GitHub Email
© 2020 John Cheung
本站访客数:
|
主题 — NexT.Pisces v5.1.4
博客全站共226.3k字