https://github.com/rzane/sdl
A generic schema definition language
https://github.com/rzane/sdl
definition dsl ruby schema
Last synced: 6 months ago
JSON representation
A generic schema definition language
- Host: GitHub
- URL: https://github.com/rzane/sdl
- Owner: rzane
- License: mit
- Created: 2019-12-15T18:39:40.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-18T02:47:33.000Z (over 5 years ago)
- Last Synced: 2025-06-13T07:50:11.637Z (7 months ago)
- Topics: definition, dsl, ruby, schema
- Language: Ruby
- Homepage: https://rubydoc.info/github/rzane/sdl
- Size: 102 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
SDL


SDL stands for *S*chema *D*efinition *L*anguage. It's a language for describing models in a system.
Alone, it doesn't do a whole lot. However, you might find helpful for building [code generators](https://github.com/rzane/geny).
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'sdl'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install sdl
## Examples
### Define a schema
```ruby
SDL.define do
model :user do
attribute :email, :string, unique: true
has_many :posts
timestamps
end
model :post do
attribute :title, :string, limit: 120
attribute :body, :text, nullable: true
enum :status, values: [:draft, :published], default: :draft
belongs_to :user, foreign_key: true
has_one_attached :image
timestamps
end
end
```
### Load a schema from a file
```ruby
# schema.rb
model :user do
attribute :name, :string
end
```
```ruby
SDL.load_file "schema.rb"
```
### Parse command-line arguments
```ruby
SDL.parse "user", %w[
email:unique
posts:has_many
]
SDL.parse "post", %w[
title:string{120}
body:text:nullable
status:enum{draft,published}
user:belongs_to:foreign_key
image:has_one_attached
]
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/rzane/sdl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the SDL project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rzane/sdl/blob/master/CODE_OF_CONDUCT.md).