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
Copy file name to clipboardExpand all lines: README.md
+47-27Lines changed: 47 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,60 +1,57 @@
1
1
> ⚠️ Master branch requires Crystal master to compile. See [installation instructions for Crystal](https://crystal-lang.org/docs/installation/from_source_repository.html).
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:
21
+
Atom::Model 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:
27
22
28
23
```crystal
29
-
repo = Core::Repository.new(db)
24
+
repo = Atom::Repository.new(db)
30
25
users = repo.query(User.where(id: 42)).first
31
26
users.class # => User
32
27
```
33
28
34
-
Core also has a plently of features, including:
29
+
Atom::Model also has a plently of features, including:
35
30
36
31
- Expressive and **type-safe** Query builder, allowing to use constructions like `Post.join(:author).where(author: user)`, which turns into a plain SQL
37
32
- References preloader (the example above would return a `Post` which has `#author = <User @id=42>` attribute set)
38
33
- Beautiful schema definition syntax
39
34
40
-
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.
35
+
However, Atom::Model 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.
41
36
42
-
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`).
37
+
Also note that although Atom::Model 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/model/ext/pg` and `/src/model/repository.cr`).
43
38
44
39
## Installation
45
40
46
41
Add this to your application's `shard.yml`:
47
42
48
43
```yaml
49
44
dependencies:
50
-
core:
51
-
github: vladfaust/core
45
+
atom-model:
46
+
github: atomframework/model
52
47
version: ~> 0.5.0
53
48
```
54
49
55
-
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.
50
+
This shard follows [Semantic Versioning v2.0.0](http://semver.org/), so check [releases](https://github.com/atomframework/model/releases) and change the `version` accordingly.
51
+
52
+
## Using
56
53
57
-
## Basic example
54
+
### Basic example
58
55
59
56
Assuming following database migration:
60
57
@@ -79,10 +76,10 @@ Crystal code:
79
76
80
77
```crystal
81
78
require "pg"
82
-
require "core"
79
+
require "atom-model"
83
80
84
81
class User
85
-
include Core::Schema
82
+
include Atom::Model
86
83
87
84
schema users do
88
85
pkey uuid : UUID # UUIDs are supported out of the box
### With [Atom](https://github.com/atomframework/atom)
140
+
141
+
Define your models as above, but with `Model` as an alias of `Atom::Model` and [`Validations`](https://github.com/vladfaust/validations.cr) included by default. You also don't need to initialize repository explicitly when using Atom:
142
+
143
+
```crystal
144
+
require "atom"
145
+
146
+
Atom.model(PG)
147
+
148
+
class User
149
+
include Model
150
+
151
+
schema do
152
+
type name : String
153
+
end
154
+
155
+
validate name, size: (3..50)
156
+
end
157
+
158
+
users = query(User.all) # Top-level `query`, `exec` and `scalar` methods
159
+
User.new("Jo").valid? # Validations
160
+
```
161
+
142
162
## Testing
143
163
144
164
1. Run generic specs with `crystal spec`
145
165
2. Apply migrations from `./db_spec/*/migration.sql`
146
-
3. Run DB-specific specs with `env POSTGRESQL_URL=postgres://postgres:postgres@localhost:5432/core crystal spec db_spec`
166
+
3. Run DB-specific specs with `env POSTGRESQL_URL=postgres://postgres:postgres@localhost:5432/model crystal spec db_spec`
147
167
4. Optionally run benchmarks with `crystal bench.cr --release`
148
168
149
169
## Contributing
150
170
151
-
1. Fork it ( https://github.com/vladfaust/core/fork )
171
+
1. Fork it ( https://github.com/atomframework/model/fork )
152
172
2. Create your feature branch (git checkout -b my-new-feature)
153
173
3. Commit your changes (git commit -am 'Add some feature')
154
174
4. Push to the branch (git push origin my-new-feature)
0 commit comments