shesuyo / crud Goto Github PK
View Code? Open in Web Editor NEWa crud lib
License: MIT License
a crud lib
License: MIT License
// Query 用于底层查询,一般是SELECT语句
func (api *CRUD) Query(sql string, args ...interface{}) SQLRows {
db := api.DB()
api.LogSQL(sql, args...)
rows, err := db.Query(sql, args...)
/
dial tcp 192.168.2.14:3306: connectex: Only one usage of each socket address (protocol/network address/port) is normally permitted.
*/
if err != nil {
api.stack(err, sql, args...)
}
return &SQLRows{rows: rows, err: err}
}
三个层次 传入参数 数据库 传出参数
四个方面 增 删 改 查(内部实现和路由层次)
CRUD拥有Create 、Read、 Update、Delete,remove to
FormCreate 、FormRead、 FormUpdate、FormDelete
需要新增Create 、Read、 Update、Delete 参数为结构体
底层全部调用Table Create 、Read、 Update、Delete
底层需要针对is_delete,delete_at,create_at
包括create、read、update、delete。
Lets say that you are invoking a web service from another web service. Both are on the same box. You might be making authenticated
or unauthenticated calls and perhaps you are setting the KeepAlive = false.
Intermittently, (under load) you might get “Only one usage of each socket address (protocol/network address/port) is normally permitted (typically under load).”
You might be wondering why are you getting a SOCKET Exception…
Here is the scoop
When a connection is closed, on the side that is closing the connection the 5 tuple
{ Protocol, Local IP, Local Port, Remote IP, Remote Port} goes into a TIME_WAIT state for 240 seconds by default.
In this case, the protocol is fixed – TCP
the local IP, remote IP and remote PORT are also typically fixed. So the variable is the local port.
What happens is that when you don’t bind a port in the range 1024-5000 is used.
So roughly you have 4000 ports. If you use all of them in 4 minutes – meaning roughly you
make 16 web service calls per second for 4 minutes you will exhaust all the ports. That is the cause of this exception.
OK now how can this be fixed?
One of the ways is to increase the dynamic port range. The max by default is 5000. You can set this up to 65534.
HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort is the key to use.
The second thing you can do is once the connection does get into an TIME_WAIT state you can reduce the time it is
in that state, Default is 4 monutes, but you can set this to 30 seconds
HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\TCPTimedWaitDelay is the key to use.
Set this to 30 seconds
If you don’t have access to registry you can do this through code.
In System.Net 2.0 we addeed what is called a BindIPEndPOintDelegate
What this does is to give you a chance to choose the local end point for the
connection that is being made.
See http://blogs.msdn.com/malarch/archive/2005/09/13/466664.aspx
for more info.
Using this, the following sample code attempts to choose between 5001 and 65534
and wrap around when we reach 65534.
Req.ServicePoint.BindIPEndPointDelegate
= new BindIPEndPoint(BindIPEndPointCallback);
public static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint,
IPEndPoint remoteEndPoint,
int retryCount)
{
int port = Interlocked.Increment(ref m_LastBindPortUsed); //increment
Interlocked.CompareExchange(ref m_LastBindPortUsed, 5001, 65534);
if(remoteEndPoint.AddressFamily == AddressFamily.InterNetwork) {
return new IPEndPoint(IPAddress.Any,port);
}
else {
return new IPEndPoint(IPAddress.IPv6Any,port);
}
}
Durgaprasad Gorti
[email protected]
Test Lead
System.Net
方案一:
使用context传递用户数据。
方案二:
在每个CRUD中将用户信息加入,然后返回*CRUD
这个时候在执行一些操作的时候,就去找这个字段,如果这个字段为空的话就不处理,如果有用户信息的话就记录下[TIME] XXX操作了XXX
RowsField(val,field)
Filter(field,val)
RowField(val,field)
支持FIELDS JOIN WHERE LIMIT OFFSET
底层创建的时候会自动会为CreatedAt设置值
更新的时候会自动为UpdatedAt设置值
删除的时候会自动设置IsDeleted和DeletedAt
如果table进行搜索了(table.RowsMap()),那么table下面所有的条件都会一直使用之前的搜索语句。
mdl.MSSFloor.RowsMap()
floorid := 2
mdl.MSSFloor.Debug(true)
if floorid != 0 {
fmt.Println(mdl.MSSFloor.Fields("name").WhereID(floorid).String())
}
output 1
package crud
import (
"bytes"
"strings"
)
type SQLBuild struct {
count int
colums []string
container *bytes.Buffer
}
func NewSQLBuild(tableName string, colums ...string) *SQLBuild {
build := new(SQLBuild)
build.count = 0
for _, v := range colums {
build.colums = append(build.colums, v)
}
build.container = bytes.NewBufferString("INSERT INTO " + tableName + "
(")
for idx := range colums {
colums[idx] = "" + colums[idx] + "
"
}
build.container.WriteString(strings.Join(colums, ","))
build.container.WriteString(") VALUES")
return build
}
func (b *SQLBuild) AddValue(args ...string) {
b.count++
b.container.WriteByte('(')
length := len(args) - 1
for idx, arg := range args {
b.container.WriteByte(''')
b.container.Write(([]byte(arg)))
b.container.WriteByte(''')
if idx < length {
b.container.WriteByte(',')
}
}
b.container.WriteByte(')')
b.container.WriteByte(',')
}
func (b *SQLBuild) AddMap(m map[string]string) {
args := []string{}
for _, colnm := range b.colums {
args = append(args, m[colnm])
}
b.AddValue(args...)
}
func (b *SQLBuild) String() string {
sql := b.container.String()
return sql[:len(sql)-1]
}
func (b *SQLBuild) Count() int {
return b.count
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.