You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Meet new Core rewritten from scratch! Featuring new schema declaration syntax, type-safe querying, spec splitting and overall code reduction!
Removed functionality:
- Validations have been removed. Use external shards instead if needed. Closes#46
- Repository `#insert`, `#update`, `#delete` and all query other than `#query` methods are removed in favour of type safety, thus closing #47 and closing #61 and also closing #33
- Converters concept has been liquidated, types now rely on `#to_db` and `#from_rs` methods via monkey patching, which closes#60
New schema declaration syntax closes#58 and closes#52. Rewritten Query resolves#48. The overhaul itself closes#55 as well
Hope you guys enjoy it!
> ⚠️ Master branch requires Crystal master to compile. See [installation instructions for Crystal](https://crystal-lang.org/docs/installation/from_source_repository.html).
Core is an expressive modular ORM for [Crystal](https://crystal-lang.org) featuring:
11
-
12
-
- ⚡️ **Efficiency** based on [Crystal](https://crystal-lang.org) performance
13
-
- ✨ **Expressiveness** with powerful DSL and lesser code
14
-
- 💼 **Safety** with strictly typed attributes
15
-
16
15
## About
17
16
18
-
Core does not follow Active Record pattern, it's more like a data-mapping solution. There is a concept of Repository, which is basically a gateway to the database. For example:
17
+
Core is a [crystal-db](https://github.com/crystal-lang/crystal-db) ORM which does not follow Active Record pattern, it's more like a data-mapping solution. There is a concept of Repository, which is basically a gateway to the database. For example:
19
18
20
19
```crystal
21
20
repo = Core::Repository.new(db)
22
-
users = repo.query(User, "SELECT * FROM users WHERE id > 42")
23
-
users.class # => Array(User)
21
+
users = repo.query(User.where(id: 42)).first
22
+
users.class # => User
24
23
```
25
24
26
25
Core also has a plently of features, including:
27
26
28
-
- Expressive Query builder, either standalone or module, allowing to use constructions like `Post.join(:author).where(author: user)`, which turns into a plain SQL
29
-
- References preloader (the example above would return a `Post` which has `#author = <User @id=42>` attribute)
30
-
- Validations module allowing to perform both inline and custom validations (`user.valid? # => true`)
27
+
- Expressive and **type-safe** Query builder, allowing to use constructions like `Post.join(:author).where(author: user)`, which turns into a plain SQL
28
+
- References preloader (the example above would return a `Post` which has `#author = <User @id=42>` attribute set)
29
+
- Beautiful schema definition syntax
30
+
31
+
However, Core is designed to be minimal, so it doesn't perform tasks you may got used to, for example, it doesn't do database migrations itself. You may use [migrate](https://github.com/vladfaust/migrate.cr) instead. Also its Query builder is not intended to fully replace SQL but instead to help a developer to write less and safer code.
31
32
32
-
However, Core is designed to be minimal, so it doesn't perform task you may got used to, for example, it doesn't do database migrations itself. You may use [migrate](https://github.com/vladfaust/migrate.cr) instead.
33
+
Also note that although Core code is designed to be abstract sutiable for any [crystal-db](https://github.com/crystal-lang/crystal-db) driver, it currently works with PostgreSQL only. But it's fairly easy to implement other drivers like MySQL or SQLite (see `/src/core/ext/pg` and `/src/core/repository.cr`).
33
34
34
35
## Installation
35
36
@@ -39,88 +40,99 @@ Add this to your application's `shard.yml`:
39
40
dependencies:
40
41
core:
41
42
github: vladfaust/core
42
-
version: ~> 0.4.2
43
+
version: ~> 0.5.0
43
44
```
44
45
45
46
This shard follows [Semantic Versioning v2.0.0](http://semver.org/), so check [releases](https://github.com/vladfaust/core/releases) and change the `version` accordingly.
0 commit comments