MySQL adapter for CRystal Object Mapper
WIP
Warning: It does not create the table, for such work use an other tool like micrate
- Insert Basic Object
- Update Basic Object
- Delete Basic Object
- Fetch by Id
- Aggregation support
Add this to your application's shard.yml
:
dependencies:
crom-mysql:
github: TechMagister/crom-mysql.cr
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
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`)
)
- 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
- TechMagister Arnaud Fernandés - creator, maintainer