topaz
Version, currently 0.2.713 versions
- 0.2.7latestApr 13, 2017
- 0.2.6not indexedSep 16, 2017
- 0.2.5not indexedSep 16, 2017
- 0.2.4not indexedSep 16, 2017
- 0.2.3not indexedSep 16, 2017
- 0.2.2not indexedSep 16, 2017
- 0.2.1not indexedSep 16, 2017
- 0.2.0not indexedSep 16, 2017
- 0.1.0not indexedSep 16, 2017
- 0.0.5not indexedSep 16, 2017
- 0.0.4not indexedSep 16, 2017
- 0.0.2not indexedSep 16, 2017
- 0.0.1not indexedSep 16, 2017
github.com/topaz-crystal/topaz
A simple and useful db wrapper for Crystal-lang
61 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
topaz:
github: topaz-crystal/topaz
version: ~> 0.2.7Then run:
shards installshard.yml
- Crystal
- no constraint declared
- License
- MIT
- Author
- Taichiro Suzuki <taichiro0709@gmail.com>
Dependencies
Runtime Dependencies
- db*github: crystal-lang/crystal-db
- singleton*github: topaz-crystal/crystal-singleton
Development Dependencies
README
<img src="https://cloud.githubusercontent.com/assets/3483230/20856901/fad1885e-b95f-11e6-848d-c46e33d8290e.png" width="100px"/>
# Topaz [](https://travis-ci.org/topaz-crystal/topaz) []()
[](https://shards.rocks/github/topaz-crystal/topaz)
[](https://shards.rocks/github/topaz-crystal/topaz)
Topaz is a simple and useful db wrapper for crystal lang.
Topaz is inspired by active record design pattern, but not fully implemented.
See [sample code](https://github.com/topaz-crystal/topaz/blob/master/samples) for detail.
[Here](https://github.com/topaz-crystal/topaz-kemal-sample) is another sample that shows how Topaz works in Kemal.
Depends on [crystal-lang/crystal-mysql](https://github.com/crystal-lang/crystal-mysql), [crystal-lang/crystal-sqlite3](https://github.com/crystal-lang/crystal-sqlite3) and [crystal-pg](https://github.com/will/crystal-pg)
## Usage
**1. Setup DB**
```crystal
Topaz::Db.setup("mysql://root@localhost/topaz") # For MySQL
Topaz::Db.setup("postgres://root@localhost/topaz") # For PostgreSQL
Topaz::Db.setup("sqlite3://./db/data.db") # For SQLite3
```
**2. Define models**
```crystal
class SampleModel < Topaz::Model
columns(
name: String
)
end
# You can drop or create a table
SampleModel.create_table
SampleModel.drop_table
```
**3. Create, find, update and delete models**
```crystal
s = SampleModel.create("Sample Name")
SampleModel.find(1).name
# => "Sample Name"
SampleModel.where("name = 'Sample Name'").size
# => 1
```
See [sample code](https://github.com/topaz-crystal/topaz/blob/master/samples/model.cr) for detail.
**4. Define associations between models**
```crystal
require "topaz"
class SampleParent < Topaz::Model
columns # Empty columns
has_many(childlen: {model: SampleChild, key: parent_id})
end
class SampleChild < Topaz::Model
columns( # Define foreign key
parent_id: Int32
)
belongs_to(parent: {model: SampleParent, key: parent_id})
end
p = SampleParent.create
child1 = SampleChild.create(p.id)
child2 = SampleChild.create(p.id)
child3 = SampleChild.create(p.id)
p.childlen.size
# => 3
child1.parent.id
# => 1
```
See [sample code](https://github.com/topaz-crystal/topaz/blob/master/samples/association.cr) for detail.
**Other features**
* Transaction
* Table migration
* `Model#to_json` and `Model#from_json`
* `created_at` and `updated_at` column
* Nullable column
* Column with default value
* Change id from Int32 to Int64
See [sample codes](https://github.com/topaz-crystal/topaz/tree/master/samples) for detail.
**Supported data types.**
String, Int32, Int64, Float32, Float64
## Development
Setting up PostgreSQL:
```
$ psql
# CREATE USER root WITH CREATEDB;
# CREATE DATABASE topaz_test WITH OWNER = root;
```
Setting up MySQL:
```
$ mysql -u root
mysql> create database topaz_test;
```
## Contributing
1. Fork it ( https://github.com/topaz-crystal/topaz/fork )
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
- [tbrand](https://github.com/tbrand) Taichiro Suzuki - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.2.7- Tagged
- Apr 13, 2017
- Commit
9d9a4bacb145- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/topaz-crystal/topaz
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 13