Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yorci/surrealdb.cr
SurrealDB driver for Crystal
https://github.com/yorci/surrealdb.cr
crystal database database-connector surreal surrealdb
Last synced: 3 months ago
JSON representation
SurrealDB driver for Crystal
- Host: GitHub
- URL: https://github.com/yorci/surrealdb.cr
- Owner: yorci
- License: mit
- Created: 2022-09-15T13:06:49.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-27T08:03:37.000Z (about 1 year ago)
- Last Synced: 2024-04-23T15:33:05.080Z (7 months ago)
- Topics: crystal, database, database-connector, surreal, surrealdb
- Language: Crystal
- Homepage:
- Size: 41 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-surreal - surrealdb.cr - Client library for [Crystal](https://crystal-lang.org) with support for HTTP and WebSocket connections. (Client libraries)
- awesome-crystal - surrealdb.cr - Unoffical SurrealDB HTTP & Websocket Client (Database Drivers/Clients)
README
# surrealdb
The unofficial SurrealDB library for Crystal.
## Todo
- [x] HTTP client tests
- [ ] Websocket client tests*Contributions are welcome*
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
surrealdb:
github: yorci/surrealdb.cr
```2. Run `shards install`
## Usage
### Connection
```crystal
require "surrealdb"# FOR HTTP Client
sdb = SurrealDB.create(
url: "http://0.0.0.0:8000/sql",
client: SurrealDB::HTTP,
)# FOR Websocket Client
sdb = SurrealDB.create(
url: "http://0.0.0.0:8000/rpc",
client: SurrealDB::WS,
)# Set authorization variables
sdb.signin "root", "root"
sdb.use "test", "test"# Creates a records in a given table
sdb.create(
"person",
{"title" => "Founder & CEO",
"name" => {
"first" => "Tobie",
"last" => "Morgan Hitchcock",
},
"marketing" => true,
"identifier" => SurrealDB.guid,
}
)# Selects all records in given table
sdb.select("person")# Update a person record with a specific id
# note `#change` or `#update` both the same for http client
sdb.update(
"person:jaime",
{"marketing" => false}
)# [WS] Perform a custom advanced query
sdb.query(
"SELECT marketing, count() FROM type::table($tb) GROUP BY marketing",
{"tb" => "person"}
)# [HTTP] Perform a custom advanced query
# note: you cannot use query parameter for http client
sdb.query(
"SELECT marketing, count() FROM person GROUP BY marketing",
nil
)# [WS] Perform a custom advanced query
# this will return *WSErrorResponse*
sdb.query(
"SELECT marketing, counr() FROM type::table($tb) GROUP BY marketing",
{"tb" => "person"}
)# [HTTP] Perform a custom advanced query
# note: you cannot use query parameter for http client
# this will return *HTTPErrorResponse*
sdb.query(
"SELECT marketing, counr() FROM person GROUP BY marketing",
nil
)
```## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Muhammed Yaşar](https://github.com/yorci) - creator and maintainer