This repository has been archived by the owner. It is now read-only.
crom-mysql.cr
crom-mysql
MySQL adapter for CRystal Object Mapper
WIP
Warning: It does not create the table, for such work use an other tool like micrate
Features
- Insert Basic Object
- Update Basic Object
- Delete Basic Object
- Fetch by Id
- Aggregation support
Installation
Add this to your application's shard.yml
:
dependencies:
crom-mysql:
github: TechMagister/crom-mysql.cr
Usage
Because it's a WIP, see spec for more details.
require "crom-mysql"
class User
CROM.mapping(:mysql, {
id: {type: Int64, nilable: true},
name: String,
age: Int32,
})
end
class Users < CROM::MySQL::Repository(User)
end
crom = CROM.container("mysql://root@localhost/crom_spec")
users = Users.new crom
user = User.new(name: "Toto", age: 15)
user = users.insert(user)
id = user.id # not nil
Development
To run spec, you should create a database named crom_spec and configure the URI in spec_helper.cr
DB_URI = "mysql://root@localhost/crom_spec"
Create the following tables :
CREATE TABLE `user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `book` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`author_id` bigint(20) NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `author` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
)
Contributing
- Fork it ( https://github.com/TechMagister/crom-mysql.cr/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
- TechMagister Arnaud Fernandés - creator, maintainer
Repository
crom-mysql.cr
Owner
Statistic
- 0
- 0
- 0
- 0
- 3
- about 8 years ago
- November 5, 2016
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 04:30:19 GMT
Languages