pon

Maiha's private ORM
0.1.3 released
maiha/pon.cr
3 1
maiha

pon.cr

Maiha's private ORM for Crystal.

  • crystal: 0.24.2

Installation

Add this to your application's shard.yml:

dependencies:
  pon:
    github: maiha/pon.cr
	version: 0.1.0

  # one of following adapter
  mysql:
    github: crystal-lang/crystal-mysql
    version: ~> 0.4.0
  sqlite3:
	github: crystal-lang/crystal-sqlite3
	version: ~> 0.9.0
  pg:
	github: will/crystal-pg
	version: ~> 0.14.1

Usage

require "pon"
require "pon/adapter/mysql"

class Job < Pon::Model
  adapter mysql
  field   name : String
  field   time : Time::Span
end

Pon::Adapter::Mysql::DEFAULT.url = "mysql://root@127.0.0.1:3306/test"
Job.migrate!  # drop and create the table

Job.count # => 0

job = Job.new(name: "foo")
job.name  # => "foo"
job.time? # => nil

# job.save # TODO

API

class Pon::Model
  # Databases
  def self.adapter : Adapter(T)
  def self.migrator : Migrator
  def self.migrate! : Nil
  def self.exec(sql) : Nil
  def self.quote(v) : String

  # Core
  def self.table_name : String
  def self.quoted_table_name : String

  # CRUD
  def self.count : Int32
  def save : Bool

  # Field "foo"
  def foo : T
  def foo? : T?

Roadmap

  • Adapter Core
    • [x] connect lazily
    • [x] exec plain sql
    • [ ] exec prepared statement
    • [x] count
    • [ ] scalar
    • [x] quote
    • [ ] escape
    • [x] migrator
  • Adapter Drivers
    • [x] mysql
    • [ ] pg
    • [ ] sqlite
  • Core
    • [x] pluralize table names
    • [ ] custom type
    • [ ] multibytes
    • [ ] record status
    • [ ] inspect class and records
    • [ ] callbacks
    • [ ] validations
  • CRUD
    • [ ] all
    • [x] count
    • [ ] create
    • [ ] delete
    • [ ] find
    • [ ] save

Development

TODO: Write development instructions here

Contributing

  1. Fork it ( https://github.com/maiha/pon.cr/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

  • maiha maiha - creator, maintainer

Thanks / Inspiration

pon:
  github: maiha/pon.cr
  version: ~> 0.1.3
License MIT
Crystal none

Authors

Dependencies 2

  • db ~> 0.5.0
    {'github' => 'crystal-lang/crystal-db', 'version' => '~> 0.5.0'}
  • lucky_inflector ~> 0.1.1
    {'github' => 'luckyframework/lucky_inflector', 'version' => '~> 0.1.1'}

Development Dependencies 3

  • mysql ~> 0.4.0
    {'github' => 'crystal-lang/crystal-mysql', 'version' => '~> 0.4.0'}
  • pg ~> 0.14.1
    {'github' => 'will/crystal-pg', 'version' => '~> 0.14.1'}
  • sqlite3 ~> 0.9.0
    {'github' => 'crystal-lang/crystal-sqlite3', 'version' => '~> 0.9.0'}

Dependents 1

Last synced .
search fire star recently