本文整理汇总了Golang中github.com/johnnadratowski/golang-neo4j-bolt-driver/errors.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: QueryPipeline
func (s *boltStmt) QueryPipeline(params ...map[string]interface{}) (PipelineRows, error) {
if s.closed {
return nil, errors.New("Neo4j Bolt statement already closed")
}
if s.rows != nil {
return nil, errors.New("Another query is already open")
}
if len(params) != len(s.queries) {
return nil, errors.New("Must pass same number of params as there are queries")
}
for i, query := range s.queries {
err := s.conn.sendRunPullAll(query, params[i])
if err != nil {
return nil, errors.Wrap(err, "Error running query:\n\n%s\n\nWith Params:\n%#v", query, params[i])
}
}
log.Info("Successfully ran all pipeline queries")
resp, err := s.conn.consume()
if err != nil {
return nil, errors.Wrap(err, "An error occurred consuming initial pipeline command")
}
success, ok := resp.(messages.SuccessMessage)
if !ok {
return nil, errors.New("Got unexpected return message when consuming initial pipeline command: %#v", resp)
}
s.rows = newPipelineRows(s, success.Metadata, 0)
return s.rows, nil
}
示例2: NextNeo
// NextNeo gets the next row result
// When the rows are completed, returns the success metadata
// and io.EOF
func (r *boltRows) NextNeo() ([]interface{}, map[string]interface{}, error) {
if r.closed {
return nil, nil, errors.New("Rows are already closed")
}
if !r.consumed {
r.consumed = true
if err := r.statement.conn.sendPullAll(); err != nil {
r.finishedConsume = true
return nil, nil, err
}
}
respInt, err := r.statement.conn.consume()
if err != nil {
return nil, nil, err
}
switch resp := respInt.(type) {
case messages.SuccessMessage:
log.Infof("Got success message: %#v", resp)
r.finishedConsume = true
return nil, resp.Metadata, io.EOF
case messages.RecordMessage:
log.Infof("Got record message: %#v", resp)
return resp.Fields, nil, nil
default:
return nil, nil, errors.New("Unrecognized response type getting next query row: %#v", resp)
}
}
示例3: decodeNode
func (d Decoder) decodeNode(buffer *bytes.Buffer) (graph.Node, error) {
node := graph.Node{}
nodeIdentityInt, err := d.decode(buffer)
if err != nil {
return node, err
}
node.NodeIdentity = nodeIdentityInt.(int64)
labelInt, err := d.decode(buffer)
if err != nil {
return node, err
}
labelIntSlice, ok := labelInt.([]interface{})
if !ok {
return node, errors.New("Expected: Labels []string, but got %T %+v", labelInt, labelInt)
}
node.Labels, err = sliceInterfaceToString(labelIntSlice)
if err != nil {
return node, err
}
propertiesInt, err := d.decode(buffer)
if err != nil {
return node, err
}
node.Properties, ok = propertiesInt.(map[string]interface{})
if !ok {
return node, errors.New("Expected: Properties map[string]interface{}, but got %T %+v", propertiesInt, propertiesInt)
}
return node, nil
}
示例4: Rollback
// Rollback rolls back and closes the transaction
func (t *boltTx) Rollback() error {
if t.closed {
return errors.New("Transaction already closed")
}
if t.conn.statement != nil {
if err := t.conn.statement.Close(); err != nil {
return errors.Wrap(err, "An error occurred closing open rows in transaction Rollback")
}
}
successInt, pullInt, err := t.conn.sendRunPullAllConsumeSingle("ROLLBACK", nil)
if err != nil {
return errors.Wrap(err, "An error occurred rolling back transaction")
}
success, ok := successInt.(messages.SuccessMessage)
if !ok {
return errors.New("Unrecognized response type rolling back transaction: %#v", success)
}
log.Infof("Got success message rolling back transaction: %#v", success)
pull, ok := pullInt.(messages.SuccessMessage)
if !ok {
return errors.New("Unrecognized response type pulling transaction: %#v", pull)
}
log.Infof("Got success message pulling transaction: %#v", pull)
t.conn.transaction = nil
t.closed = true
return err
}
示例5: decodeUnboundRelationship
func (d Decoder) decodeUnboundRelationship(buffer *bytes.Buffer) (graph.UnboundRelationship, error) {
rel := graph.UnboundRelationship{}
relIdentityInt, err := d.decode(buffer)
if err != nil {
return rel, err
}
rel.RelIdentity = relIdentityInt.(int64)
var ok bool
typeInt, err := d.decode(buffer)
if err != nil {
return rel, err
}
rel.Type, ok = typeInt.(string)
if !ok {
return rel, errors.New("Expected: Type string, but got %T %+v", typeInt, typeInt)
}
propertiesInt, err := d.decode(buffer)
if err != nil {
return rel, err
}
rel.Properties, ok = propertiesInt.(map[string]interface{})
if !ok {
return rel, errors.New("Expected: Properties map[string]interface{}, but got %T %+v", propertiesInt, propertiesInt)
}
return rel, nil
}
示例6: Begin
// Begin begins a new transaction with the Neo4J Database
func (c *boltConn) Begin() (driver.Tx, error) {
if c.transaction != nil {
return nil, errors.New("An open transaction already exists")
}
if c.statement != nil {
return nil, errors.New("Cannot open a transaction when you already have an open statement")
}
if c.closed {
return nil, errors.New("Connection already closed")
}
successInt, pullInt, err := c.sendRunPullAllConsumeSingle("BEGIN", nil)
if err != nil {
return nil, errors.Wrap(err, "An error occurred beginning transaction")
}
success, ok := successInt.(messages.SuccessMessage)
if !ok {
return nil, errors.New("Unrecognized response type beginning transaction: %#v", success)
}
log.Infof("Got success message beginning transaction: %#v", success)
success, ok = pullInt.(messages.SuccessMessage)
if !ok {
return nil, errors.New("Unrecognized response type pulling transaction: %#v", success)
}
log.Infof("Got success message pulling transaction: %#v", success)
return newTx(c), nil
}
示例7: Write
// Write to the net conn, recording the interaction
func (r *recorder) Write(b []byte) (n int, err error) {
if r.Conn != nil {
numWritten, err := r.Conn.Write(b)
if numWritten > 0 {
r.record(b[:numWritten], true)
}
if err != nil {
r.recordErr(err, true)
}
return numWritten, err
}
if r.currentEvent >= len(r.events) {
return 0, errors.New("Trying to write past all of the events in the recorder! %#v", r)
}
event := r.events[r.currentEvent]
if !event.IsWrite {
return 0, errors.New("Recorder expected Write, got Read! %#v, Event: %#v", r, event)
}
for i := 0; i < len(b); i++ {
if len(event.Event) == 0 {
return i, errors.New("Attempted to write past current event in recorder! %#v, Event: %#v", r, event)
}
event.Event = event.Event[1:]
}
if len(event.Event) == 0 {
r.currentEvent++
}
return len(b), nil
}
示例8: ExecNeo
// ExecNeo executes a query that returns no rows. Implements a Neo-friendly alternative to sql/driver.
func (s *boltStmt) ExecNeo(params map[string]interface{}) (Result, error) {
if s.closed {
return nil, errors.New("Neo4j Bolt statement already closed")
}
if s.rows != nil {
return nil, errors.New("Another query is already open")
}
runResp, pullResp, _, err := s.conn.sendRunPullAllConsumeAll(s.query, params)
if err != nil {
return nil, err
}
success, ok := runResp.(messages.SuccessMessage)
if !ok {
return nil, errors.New("Unrecognized response type when running exec query: %#v", success)
}
log.Infof("Got run success message: %#v", success)
success, ok = pullResp.(messages.SuccessMessage)
if !ok {
return nil, errors.New("Unrecognized response when discarding exec rows: %#v", success)
}
log.Infof("Got discard all success message: %#v", success)
return newResult(success.Metadata), nil
}
示例9: PreparePipeline
// PreparePipeline prepares a new pipeline statement for a query.
func (c *boltConn) PreparePipeline(queries ...string) (PipelineStmt, error) {
if c.statement != nil {
return nil, errors.New("An open statement already exists")
}
if c.closed {
return nil, errors.New("Connection already closed")
}
c.statement = newPipelineStmt(queries, c)
return c.statement, nil
}
示例10: prepare
func (c *boltConn) prepare(query string) (*boltStmt, error) {
if c.statement != nil {
return nil, errors.New("An open statement already exists")
}
if c.closed {
return nil, errors.New("Connection already closed")
}
c.statement = newStmt(query, c)
return c.statement, nil
}
示例11: parseURL
func (c *boltConn) parseURL() (*url.URL, error) {
user := ""
password := ""
url, err := url.Parse(c.connStr)
if err != nil {
return url, errors.Wrap(err, "An error occurred parsing bolt URL")
} else if strings.ToLower(url.Scheme) != "bolt" {
return url, errors.New("Unsupported connection string scheme: %s. Driver only supports 'bolt' scheme.", url.Scheme)
}
if url.User != nil {
c.user = url.User.Username()
var isSet bool
c.password, isSet = url.User.Password()
if !isSet {
return url, errors.New("Must specify password when passing user")
}
}
timeout := url.Query().Get("timeout")
if timeout != "" {
timeoutInt, err := strconv.Atoi(timeout)
if err != nil {
return url, errors.New("Invalid format for timeout: %s. Must be integer", timeout)
}
c.timeout = time.Duration(timeoutInt) * time.Second
}
useTLS := url.Query().Get("tls")
c.useTLS = strings.HasPrefix(strings.ToLower(useTLS), "t") || useTLS == "1"
if c.useTLS {
c.certFile = url.Query().Get("tls_cert_file")
c.keyFile = url.Query().Get("tls_key_file")
c.caCertFile = url.Query().Get("tls_ca_cert_file")
noVerify := url.Query().Get("tls_no_verify")
c.tlsNoVerify = strings.HasPrefix(strings.ToLower(noVerify), "t") || noVerify == "1"
}
log.Trace("Bolt Host: ", url.Host)
log.Trace("Timeout: ", c.timeout)
log.Trace("User: ", user)
log.Trace("Password: ", password)
log.Trace("TLS: ", c.useTLS)
log.Trace("TLS No Verify: ", c.tlsNoVerify)
log.Trace("Cert File: ", c.certFile)
log.Trace("Key File: ", c.keyFile)
log.Trace("CA Cert File: ", c.caCertFile)
return url, nil
}
示例12: ExecPipeline
func (c *boltConn) ExecPipeline(queries []string, params ...map[string]interface{}) ([]Result, error) {
if c.statement != nil {
return nil, errors.New("An open statement already exists")
}
if c.closed {
return nil, errors.New("Connection already closed")
}
stmt := newPipelineStmt(queries, c)
defer stmt.Close()
return stmt.ExecPipeline(params...)
}
示例13: Exec
// Exec executes a query that returns no rows. See sql/driver.Stmt.
// You must bolt encode a map to pass as []bytes for the driver value
func (c *boltConn) Exec(query string, args []driver.Value) (driver.Result, error) {
if c.statement != nil {
return nil, errors.New("An open statement already exists")
}
if c.closed {
return nil, errors.New("Connection already closed")
}
stmt := newStmt(query, c)
defer stmt.Close()
return stmt.Exec(args)
}
示例14: ExecNeo
// ExecNeo executes a query that returns no rows. Implements a Neo-friendly alternative to sql/driver.
func (c *boltConn) ExecNeo(query string, params map[string]interface{}) (Result, error) {
if c.statement != nil {
return nil, errors.New("An open statement already exists")
}
if c.closed {
return nil, errors.New("Connection already closed")
}
stmt := newStmt(query, c)
defer stmt.Close()
return stmt.ExecNeo(params)
}
示例15: ExecPipeline
func (s *boltStmt) ExecPipeline(params ...map[string]interface{}) ([]Result, error) {
if s.closed {
return nil, errors.New("Neo4j Bolt statement already closed")
}
if s.rows != nil {
return nil, errors.New("Another query is already open")
}
if len(params) != len(s.queries) {
return nil, errors.New("Must pass same number of params as there are queries")
}
for i, query := range s.queries {
err := s.conn.sendRunPullAll(query, params[i])
if err != nil {
return nil, errors.Wrap(err, "Error running exec query:\n\n%s\n\nWith Params:\n%#v", query, params[i])
}
}
log.Info("Successfully ran all pipeline queries")
results := make([]Result, len(s.queries))
for i := range s.queries {
runResp, err := s.conn.consume()
if err != nil {
return nil, errors.Wrap(err, "An error occurred getting result of exec command: %#v", runResp)
}
success, ok := runResp.(messages.SuccessMessage)
if !ok {
return nil, errors.New("Unexpected response when getting exec query result: %#v", runResp)
}
_, pullResp, err := s.conn.consumeAll()
if err != nil {
return nil, errors.Wrap(err, "An error occurred getting result of exec discard command: %#v", pullResp)
}
success, ok = pullResp.(messages.SuccessMessage)
if !ok {
return nil, errors.New("Unexpected response when getting exec query discard result: %#v", pullResp)
}
results[i] = newResult(success.Metadata)
}
return results, nil
}