topaz-crystal / Topaz
Licence: mit
A simple and useful db wrapper for Crystal-lang
Stars: ✭ 56
Programming Languages
crystal
512 projects
Projects that are alternatives of or similar to Topaz
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+4957.14%)
Mutual labels: orm, database, db
Awesome Python Models
A curated list of awesome Python libraries, which implement models, schemas, serializers/deserializers, ODM's/ORM's, Active Records or similar patterns.
Stars: ✭ 124 (+121.43%)
Mutual labels: orm, activerecord, model
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (+142.86%)
Mutual labels: orm, db, model
Sequelizer
A GUI Desktop App for export sequelize models from database automatically.
Stars: ✭ 273 (+387.5%)
Mutual labels: orm, database, model
Freezer
A simple & fluent Android ORM, how can it be easier ? RxJava2 compatible
Stars: ✭ 326 (+482.14%)
Mutual labels: orm, database, model
Gorose
GoRose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides six major database drivers: mysql,sqlite3,postgres,oracle,mssql, Clickhouse.
Stars: ✭ 947 (+1591.07%)
Mutual labels: orm, database, db
Node Pg Migrate
Node.js database migration management for Postgresql
Stars: ✭ 838 (+1396.43%)
Mutual labels: database, db
Go Kallax
Kallax is a PostgreSQL typesafe ORM for the Go language.
Stars: ✭ 853 (+1423.21%)
Mutual labels: orm, database
Android dbinspector
Android library for viewing and sharing in app databases.
Stars: ✭ 881 (+1473.21%)
Mutual labels: database, db
Walrus
Lightweight Python utilities for working with Redis
Stars: ✭ 846 (+1410.71%)
Mutual labels: orm, database
Mithril Data
A rich data model library for Mithril javascript framework
Stars: ✭ 17 (-69.64%)
Mutual labels: database, model
Active record doctor
Identify database issues before they hit production.
Stars: ✭ 865 (+1444.64%)
Mutual labels: activerecord, database
Orbit Db Http Api
A HTTP API Server for the OrbitDB distributed peer-to-peer database
Stars: ✭ 17 (-69.64%)
Mutual labels: database, db
Xodus
Transactional schema-less embedded database used by JetBrains YouTrack and JetBrains Hub.
Stars: ✭ 864 (+1442.86%)
Mutual labels: database, db
Nextjs Sequelize
Next.js With Sequelize Web Application, a Full-Stack Web App Development Boilerplate. https://medium.com/@defrian.yarfi/next-js-with-sequelize-web-application-a-full-stack-web-development-a0051074e998
Stars: ✭ 21 (-62.5%)
Mutual labels: orm, database
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 for detail.
Here is another sample that shows how Topaz works in Kemal.
Depends on crystal-lang/crystal-mysql, crystal-lang/crystal-sqlite3 and crystal-pg
Usage
1. Setup DB
Topaz::Db.setup("mysql://[email protected]/topaz") # For MySQL
Topaz::Db.setup("postgres://[email protected]/topaz") # For PostgreSQL
Topaz::Db.setup("sqlite3://./db/data.db") # For SQLite3
2. Define models
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
s = SampleModel.create("Sample Name")
SampleModel.find(1).name
# => "Sample Name"
SampleModel.where("name = 'Sample Name'").size
# => 1
See sample code for detail.
4. Define associations between models
require "topaz"
class SampleParent < Topaz::Model
columns # Empty columns
has_many(children: {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.children.size
# => 3
child1.parent.id
# => 1
See sample code for detail.
Other features
- Transaction
- Table migration
-
Model#to_json
andModel#from_json
-
created_at
andupdated_at
column - Nullable column
- Column with default value
- Change id from Int32 to Int64
See sample codes 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
- Fork it ( https://github.com/topaz-crystal/topaz/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- tbrand Taichiro Suzuki - creator, maintainer
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].