Skip to content

Commit

Permalink
Merge pull request #1 from Dal-Papa/master
Browse files Browse the repository at this point in the history
Cluster params & Context name
  • Loading branch information
mikebthun committed Nov 16, 2014
2 parents 51f37f5 + 86b7d2e commit 4e825e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Depends on [Gorilla Context Package](http://www.gorillatoolkit.org/pkg/context)

### Usage

```
~~~ go
import(

"github.com/mikebthun/negronicql"
Expand All @@ -19,11 +19,6 @@ import(

)

```


```
router := mux.NewRouter()

router.HandleFunc("/", MyHandler ).Methods("POST")
Expand All @@ -49,20 +44,40 @@ func MyHandler(w http.ResponseWriter, req *http.Request) {

//grab the session here

session = context.Get( req, "Session" ).(*gocql.Session)
session = context.Get( req, "CQLSession" ).(*gocql.Session)



}
```
~~~

Run your queries like normal on the gocql session:

```
~~~ go

session.Query( `SELECT * FROM blah` ).Exec()

```
~~~

If you want to customize your ClusterConfig object, you can instantiate one, give it its attributes and Connect().

~~~ go
cqldb := negronicql.New()
cqldb.Cluster = gocql.NewCluster("127.0.0.1", "127.0.0.2")
cqldb.Cluster.Authenticator = gocql.PasswordAuthenticator{"user", "password"}
cqldb.Cluster.Port = 4242
cqldb.Cluster.Keyspace = "MyKeySpace"
cqldb.Cluster.Consistency = gocql.Quorum
// ...
cqldb.Connect()

~~~

### Contributors

Author : Mike B Thun @mikebthun

Contrib : Clem DalPalu @Dal-Papa

### License

Expand Down
10 changes: 7 additions & 3 deletions negronicql.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ func (m *Negronicql) Connect() error {

}

//create cluster config
m.Cluster = gocql.NewCluster(m.Ips[0])
//create cluster config if not created by user
if m.Cluster == nil {
m.Cluster = gocql.NewCluster(m.Ips...)
m.Cluster.Keyspace = m.Keyspace
m.Cluster.Consistency = m.Consistency
}

session, err := m.Cluster.CreateSession()

Expand All @@ -50,7 +54,7 @@ func (m *Negronicql) Connect() error {
func (m *Negronicql) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {

//attach the session
context.Set(r, "Session", m.Session)
context.Set(r, "CQLSession", m.Session)

// Call the next middleware handler
next(rw, r)
Expand Down

0 comments on commit 4e825e3

Please sign in to comment.