Skip to content

Commit fc3a704

Browse files
authored
Updated README
1 parent b73e7e0 commit fc3a704

File tree

1 file changed

+5
-105
lines changed

1 file changed

+5
-105
lines changed

README.md

Lines changed: 5 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,8 @@
11
# JavaXT ORM (Object Relational Mapping)
2-
Command line utility for generating Java code and DDL from a set of models defined in a javascript or json document.
2+
The javaxt-orm library is a handy tool for generating Java code and DDL from a set of models defined in a Javascript or JSON document. The generated classes are used to persist data in a relational database via the javaxt.sql.Model class.
33

4+
## Project homepage
5+
Information about the javaxt-orm library, documentation, and releases can be found at <a href="https://www.javaxt.com/javaxt-orm/">https://www.javaxt.com/javaxt-orm/</a>
46

5-
This is not intended to be a full fledged ORM framework. Instead, the goal is to help jumpstart new projects by
6-
providing a simple utility for stubbing out code and SQL.
7-
8-
## Command Line Interface
9-
The javaxt-orm library provides a command line interface that can be used to generate Java classes
10-
and schema. All you need to do is provide a input model and an output directory. Example:
11-
```
12-
java -jar javaxt-orm.jar /path/to/model.js /output
13-
```
14-
15-
## Model Input
16-
Below is a simple example of an input Javascript file with an Address model.
17-
```javascript
18-
var package = "com.example.models";
19-
var models = {
20-
Address: {
21-
fields: [
22-
{name: 'street', type: 'string'},
23-
{name: 'city', type: 'string'},
24-
{name: 'state', type: 'string'},
25-
{name: 'postalCode', type: 'string'},
26-
{name: 'coordinates', type: 'geo'}
27-
]
28-
}
29-
}
30-
```
31-
32-
The examples folder contains a few sample models that you can use as reference.
33-
34-
35-
## Model mapping and supported types
36-
37-
38-
Field Type | Java Type | Database Type | Comments
39-
------------|-------------|-----------------|----------------------------
40-
int | Integer | integer |
41-
long | Long | bigint |
42-
float | Double | double precision |
43-
double | Double | double precision |
44-
decimal | BigDecimal | numeric |
45-
numeric | BigDecimal | numeric |
46-
text | String | text or varchar | varchar if there is a length constraint
47-
string | String | text or varchar | varchar if there is a length constraint
48-
char | String | char(1) |
49-
boolean | Boolean | Boolean |
50-
date | Date | timestamp with time zone |
51-
binary | byte[] | bytea |
52-
json | JSONObject | jasonb |
53-
geo | Geometry | geometry(Geometry,4326) | For lat/lon geographic data
54-
geometry | Geometry | geometry(GeometryZ) | For x,y,z data
55-
password | String | text | Stores bcrypt hash
56-
57-
In addition to these standard field types, you can specify a model as a `type`. Example:
58-
59-
```javascript
60-
{
61-
Contact: {
62-
fields: [
63-
{name: 'name', type: 'string'},
64-
{name: 'address', type: 'Address'}
65-
]
66-
},
67-
Address: {
68-
...
69-
}
70-
}
71-
```
72-
73-
74-
## Supported field constraints
75-
76-
Constraint Key | Type | Comments
77-
----------------|---------|----------------------------------------------
78-
required | boolean | If true, adds a "NOT NULL" constraint to the field. Can also use "nullable" keyword.
79-
length | int | Only applies to "text" field types. When specified, reassigns the database type to varchar.
80-
unique | boolean | Should not be applied to "text" fields without a length constraint.
81-
onDelete | string | Only applies to fields with models. Options include "cascade" and "no action" (default).
82-
83-
## Misc
84-
85-
IDs are automatically added so you don't have to explicitly define one in the model.
86-
87-
Models can be assigned to fields. A foreign key will be created in the database.
88-
89-
lastUpdate fields in the model are automatically assigned a trigger in the database.
90-
91-
92-
## Dependencies
93-
The javaxt-orm library requires Java 8 or higher for Javascript parsing and javaxt-core.jar for JSON and basic file IO.
94-
95-
96-
## Generated Code Dependencies
97-
The javaxt-orm library generates Java code that extends/implements javaxt.sql.Model class.
98-
It also calls java.util.Map.ofEntries which was introduced in Java 9.
99-
Therefore, you will need both javaxt-core and Java 9 (or higher) to use the generated code
100-
in your project. In addition, you will need JTS if you include a `geo` or `geometry` type.
101-
Last but not least, you will need to include a JDBC driver in your project for persistance.
102-
103-
104-
## How to Use With Java 15 and Up
105-
The javaxt-orm library relies on Nashorn for parsing input Javascript files.
106-
Nashorn used to be bundled with Java between versions 8 to 14. Unfortunately, starting with Java 15
107-
Nashorn is no longer included in the standard distribution and needs to be downloaded as a seperate JAR via OpenJDK.
108-
More info <a href="https://gist.github.com/pborissow/a1d8a7721d131b773235cca88dc0b88c">here</a>.
7+
## License
8+
All JavaXT libraries are free and open source released under a permissive MIT license. This software comes with no guarantees or warranties. You may use this software in any open source or commercial project.

0 commit comments

Comments
 (0)