Permalink
Browse files

Development is discontinued

  • Loading branch information...
1 parent fa1f653 commit fec324426fee7565a28e8038c7bea66df304f1b7 @edsrzf committed Mar 15, 2011
Showing with 3 additions and 675 deletions.
  1. +0 −25 LICENSE
  2. +0 −16 Makefile
  3. +3 −51 README.md
  4. +0 −224 collection.go
  5. +0 −115 conn.go
  6. +0 −97 cursor.go
  7. +0 −69 database.go
  8. +0 −78 query.go
View
25 LICENSE
@@ -1,25 +0,0 @@
-Copyright (c) 2010, Evan Shaw
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- * Neither the name of the copyright holder nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
View
@@ -1,16 +0,0 @@
-# Copyright 2010, Evan Shaw. All rights reserved.
-# Use of this source code is governed by a BSD-style License
-# that can be found in the LICENSE file.
-
-include $(GOROOT)/src/Make.inc
-
-TARG=github.com/edsrzf/mongogo
-GOFILES=\
- collection.go\
- conn.go\
- cursor.go\
- database.go\
- query.go\
-
-include $(GOROOT)/src/Make.pkg
-
View
@@ -1,55 +1,7 @@
Mongogo
=======
-Mongogo is a MongoDB driver for the [Go programming language](http://golang.org/).
+Mongogo was a MongoDB driver for the [Go programming language](http://golang.org/).
-This project is still in development. It's been tested on Arch and Ubuntu Linux for
-the amd64 architecture, but there's no reason it shouldn't work on other architectures
-as well.
-
-Dependencies
-------------
-
-Mongogo compiles with Go release 2010-10-27 or newer, barring any recent language or
-library changes.
-
-Mongogo works with MongoDB version 2.6 or newer. It may partially work with older versions.
-
-Mongogo's only non-core Go dependency is [Go-BSON](go-bson).
-You can install it with goinstall by running
- goinstall github.com/edsrzf/go-bson
-
-Usage
------
-
-Create a connection:
-
- conn := mongo.Dial("127.0.0.1:27017")
-
-Get a database:
-
- db := conn.Database("blog")
-
-Get a collection:
-
- col := db.Collection("posts")
-
-Insert a document into the collection:
-
- doc := map[string]interface{}{"title": "Hello", "body": "World!"}
- col.Insert(doc)
-
-Query the database:
-
- q := mongo.Query{"title": "Hello"}
- cursor := col.Find(q, 0, 0)
- defer cursor.Close()
-
-See the documentation in the source for more information.
-
-Contributing
-------------
-
-Simply use GitHub as usual to create a fork, make your changes, and create a pull
-request. Code is expected to be formatted with gofmt and to adhere to the usual Go
-conventions -- that is, the conventions used by Go's core libraries.
+Development has ceased in favor of [Gustavo Niemeyer's mgo](http://labix.org/mgo).
+The history remains here intact for posterity.
View
@@ -1,224 +0,0 @@
-// Copyright 2010, Evan Shaw. All rights reserved.
-// Use of this source code is governed by a BSD-style License
-// that can be found in the LICENSE file.
-
-package mongo
-
-import (
- "bytes"
- "encoding/binary"
- "os"
- "github.com/edsrzf/go-bson"
-)
-
-// common message header size
-// 16-byte header
-const headerSize = 16
-
-// A Collection represents a MongoDB collection.
-type Collection struct {
- db *Database
- name string
- fullName []byte
-}
-
-// Drop deletes c from the database.
-func (c *Collection) Drop() os.Error {
- cmd := Query{"drop": string(c.fullName)}
- _, err := c.db.Command(cmd)
- return err
-}
-
-// Update updates a single document selected by query, according to doc.
-func (c *Collection) Update(query, doc bson.Doc) os.Error {
- return c.update(query, doc, false, false)
-}
-
-// Upsert updates or inserts a single document selected by query,
-// according to doc.
-func (c *Collection) Upsert(query, doc bson.Doc) os.Error {
- return c.update(query, doc, true, false)
-}
-
-// Update updates multiple documents selected by query, according to doc.
-func (c *Collection) UpdateAll(query, doc bson.Doc) os.Error {
- return c.update(query, doc, false, true)
-}
-
-// UpsertAll updates or inserts multiple documents selected by query,
-// according to doc.
-func (c *Collection) UpsertAll(query, doc bson.Doc) os.Error {
- return c.update(query, doc, true, true)
-}
-
-func (c *Collection) update(query, doc bson.Doc, upsert, multi bool) os.Error {
- selData, err := bson.Marshal(query)
- if err != nil {
- return err
- }
- docData, err := bson.Marshal(doc)
- if err != nil {
- return err
- }
- cap := headerSize + 4 + len(c.fullName) + 4 + len(selData) + len(docData)
- payload := make([]byte, headerSize+4, cap)
- buf := bytes.NewBuffer(payload)
- buf.Write(c.fullName)
- var flags int32
- if upsert {
- flags |= 1
- }
- if multi {
- flags |= 2
- }
- binary.Write(buf, order, flags)
- buf.Write(selData)
- buf.Write(docData)
- payload = payload[:cap]
- return c.db.conn.sendMessage(2001, 0, payload)
-}
-
-// Insert creates a new document in c.
-func (c *Collection) Insert(doc bson.Doc) os.Error {
- data, err := bson.Marshal(doc)
- if err != nil {
- return err
- }
- cap := headerSize + 4 + len(c.fullName) + len(data)
- payload := make([]byte, headerSize+4, cap)
- buf := bytes.NewBuffer(payload)
- buf.Write(c.fullName)
- buf.Write(data)
- payload = payload[:cap]
- return c.db.conn.sendMessage(2002, 0, payload)
-}
-
-// Find searches c for any documents matching a query. It skips the first skip
-// documents and limits the search to limit.
-func (c *Collection) Find(query Query, skip, limit int32) (*Cursor, os.Error) {
- return c.FindFields(query, nil, skip, limit)
-}
-
-// FindFields performs a query that returns only specified fields. It skips the
-// first skip documents and limits the search to limit.
-// The fields specified can be inclusive or exclusive, but not both. That is,
-// the values in the fields parameter must be all true or all false with no
-// mixing. Fields with true values will be returned, while fields with false
-// values will be excluded.
-func (c *Collection) FindFields(query Query, fields map[string]interface{}, skip, limit int32) (*Cursor, os.Error) {
- conn := c.db.conn
- data, err := bson.Marshal(bson.Doc(query))
- if err != nil {
- return nil, err
- }
- var fieldData []byte
- if fields != nil {
- fieldData, err = bson.Marshal(bson.Doc(fields))
- if err != nil {
- return nil, err
- }
- }
- cap := headerSize + 4 + len(c.fullName) + 8 + len(data) + len(fieldData)
- payload := make([]byte, headerSize, cap)
- buf := bytes.NewBuffer(payload[headerSize:])
- // TODO(eds): Consider supporting flags
- binary.Write(buf, order, int32(0))
- buf.Write(c.fullName)
- binary.Write(buf, order, skip)
- binary.Write(buf, order, limit)
- buf.Write(data)
- buf.Write(fieldData)
- payload = payload[:cap]
- if err := conn.sendMessage(2004, 0, payload); err != nil {
- return nil, err
- }
-
- reply, err := conn.readReply()
- if err != nil {
- return nil, err
- }
-
- return &Cursor{c, reply.cursorID, 0, reply.docs}, nil
-}
-
-// FindOneFields performs a query that returns only speciied fields from one
-// document.
-func (c *Collection) FindOneFields(query Query, fields map[string]interface{}) (bson.Doc, os.Error) {
- cursor, err := c.FindFields(query, fields, 0, 1)
- if err != nil {
- return nil, err
- }
- defer cursor.Close()
- return cursor.Next(), nil
-}
-
-// FindAll returns all documents in c matching a query.
-func (c *Collection) FindAll(query Query) (*Cursor, os.Error) {
- return c.Find(query, 0, 0)
-}
-
-// FindOne returns the first document in c that matches a query.
-func (c *Collection) FindOne(query Query) (bson.Doc, os.Error) {
- cursor, err := c.Find(query, 0, 1)
- if err != nil {
- return nil, err
- }
- defer cursor.Close()
- return cursor.Next(), nil
-}
-
-// Count returns the number of documents in c that match a query.
-func (c *Collection) Count(query bson.Doc) (int64, os.Error) {
- cmd := Query{"count": c.name, "query": query}
- reply, err := c.db.Command(cmd)
- if reply == nil || err != nil {
- return -1, err
- }
-
- // NOTE(eds): Mongo returns count as a double? Really? That seems silly.
- return int64(reply["n"].(float64)), nil
-}
-
-func (c *Collection) remove(query bson.Doc, singleRemove bool) os.Error {
- data, err := bson.Marshal(query)
- if err != nil {
- return err
- }
- l := len(c.fullName)
- payload := make([]byte, headerSize+4+l+4+len(data))
- copy(payload[headerSize+4:], c.fullName)
- if singleRemove {
- payload[headerSize+4+l] |= 1
- }
- copy(payload[headerSize+4+l+4:], data)
- return c.db.conn.sendMessage(2006, 0, payload)
-}
-
-// Remove removes all documents in c that match a query.
-func (c *Collection) Remove(query bson.Doc) os.Error {
- return c.remove(query, false)
-}
-
-// RemoveFirst removes the first document in c that matches a query.
-func (c *Collection) RemoveFirst(query bson.Doc) os.Error {
- return c.remove(query, true)
-}
-
-// EnsureIndex ensures that an index exists on this collection.
-func (c *Collection) EnsureIndex(name string, keys map[string]int32, unique bool) os.Error {
- col := c.db.Collection("system.indexes")
- id := bson.Doc{"name": name, "ns": string(c.fullName), "key": keys, "unique": unique}
- return col.Insert(id)
-}
-
-// DropIndexes deletes all indexes on c.
-func (c *Collection) DropIndexes() os.Error {
- return c.DropIndex("*")
-}
-
-// DropIndex deletes a single index.
-func (c *Collection) DropIndex(name string) os.Error {
- cmd := Query{"deleteIndexes": string(c.fullName), "index": name}
- _, err := c.db.Command(cmd)
- return err
-}
Oops, something went wrong.

0 comments on commit fec3244

Please sign in to comment.