pon

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

pon.cr

Maiha's private ORM for Crystal.

  • crystal: 0.24.2

Usage

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

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

Pon::Adapter::Mysql.setting.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  # => true

API

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

  # Core
  def self.table_name : String
  def self.quoted_table_name : String
  def new_record? : Bool

  # CRUD
  def self.create! : M
  def self.create : M
  def self.count : Int32
  def save : Bool
  def save! : Bool
  def self.delete_all

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

Roadmap

  • Adapter Core
    • [x] connect lazily
    • [x] exec plain sql
    • [x] exec prepared statement
    • [x] count
    • [ ] scalar
    • [x] quote
    • [ ] escape
    • [x] migrator
  • Adapter Drivers
    • RDB
      • [x] mysql
      • [x] pg
      • [x] sqlite
    • KVS
      • [ ] redis
  • Core
    • [x] pluralize table names
    • [ ] custom type
    • [x] multibytes
    • [x] record status
    • [x] inspect class and records
    • [ ] callbacks
    • [ ] validations
    • [ ] natural keys
  • CRUD
    • [x] all
    • [x] count
    • [x] create
    • [ ] delete
    • [x] find
    • [x] save
  • Relations
    • [ ] belongs_to
    • [ ] has_many
    • [ ] has_many through
  • Misc
    • [ ] bulk insert
    • [ ] upsert

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

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.5
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