https://github.com/ncodes/jsq
A mongoDB query parser for SQL databases
https://github.com/ncodes/jsq
go mongo sql
Last synced: 3 months ago
JSON representation
A mongoDB query parser for SQL databases
- Host: GitHub
- URL: https://github.com/ncodes/jsq
- Owner: ncodes
- Created: 2017-05-24T06:57:58.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-27T12:24:15.000Z (almost 9 years ago)
- Last Synced: 2025-08-15T12:25:18.632Z (8 months ago)
- Topics: go, mongo, sql
- Language: Go
- Homepage: https://github.com/ncodes/jsq
- Size: 1.08 MB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## JSQ - A mongoDB query parser for SQL databases
JSQ allows the use of similar mongoDB query expressions to find records in traditional SQL databases like Postgres, MySQL etc.
### Installation
```
go get github.com/ncodes/jsq
```
### Example
```go
jsq, err := NewJSQ([]string{
"valid_field_1",
"name",
"age",
})
// Parse a query
err := jsq.Parse(`{
"name": {
"$eq": "ben"
}
}`)
if err != nil {
log.Fatalf("failed to parse: %s", err)
}
// Get SQL
sql, args, err := jsq.ToSQL()
```
#### Supported Compare Operators
- $eq - Equal
- $gt - Greater Than
- $gte - Greater Than or Equal
- $lt - Less Than
- $lte - Less Than or Equal
- $ne - Not Equal
- $in - In array
- $nin - Not In array
- $not - Not (negate)
- $sw - Starts with
- $ew - End with
- $ct - Contains
### Logical Operators
- $and - Find records matching every expression in an array
- $or - Find records matching at least an expression in an array
- $nor - Find records that fail to match all expressions in an array
### Links
- See full operator usage and examples on the [mongoDB website](https://docs.mongodb.com/manual/reference/operator/query/)
- [Go Doc](https://godoc.org/github.com/ncodes/jsq)
### Todo:
- More query operators
- Support joins and aggregate functions