zormz 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -133
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# ZORMZ
|
|
2
2
|
|
|
3
|
-
Un ORM ligero escrito en TypeScript para MySQL y PostgreSQL
|
|
4
|
-
|
|
3
|
+
Un ORM ligero escrito en TypeScript para **MySQL** y **PostgreSQL**, diseñado para ser simple, rápido y extensible.
|
|
4
|
+
Permite conectarse a una base de datos, definir tablas desde TypeScript con autocompletado y tipado, y generar tablas automáticamente.
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
@@ -11,7 +11,11 @@ por ahora solo es posible conectarse a una base de datos.
|
|
|
11
11
|
* Tipado completo en **TypeScript**
|
|
12
12
|
* Builder con sintaxis encadenada: `select().from().where().execute()`
|
|
13
13
|
* Insert múltiple con arrays
|
|
14
|
-
*
|
|
14
|
+
* Update y Delete con condiciones
|
|
15
|
+
* Definición de columnas con encadenamiento:
|
|
16
|
+
* `int().Pk().$()`
|
|
17
|
+
* `varchar(200).Default("hola").$()`
|
|
18
|
+
* Generación automática de tablas en MySQL y PostgreSQL
|
|
15
19
|
* Sin dependencias pesadas
|
|
16
20
|
* Fácil de extender
|
|
17
21
|
|
|
@@ -21,207 +25,177 @@ por ahora solo es posible conectarse a una base de datos.
|
|
|
21
25
|
|
|
22
26
|
```bash
|
|
23
27
|
npm install zormz
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## Uso básico
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
```
|
|
31
30
|
|
|
31
|
+
## Uso basico
|
|
32
|
+
### importacion ESM
|
|
32
33
|
```ts
|
|
33
|
-
import { connecionLocal, getConexion } from "zormz";
|
|
34
|
-
```
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
import { connecionLocal, getConexion, defineTable, generateTable, int, varchar, DB, eq, ORQ } from "zormz";
|
|
37
36
|
|
|
38
|
-
```js
|
|
39
|
-
const { connecionLocal, getConexion } = require("zormz");
|
|
40
37
|
```
|
|
38
|
+
### importacion COMMONJS
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
```ts
|
|
41
|
+
const { connecionLocal, getConexion, defineTable, generateTable, int, varchar, DB, eq, ORQ } = require("zormz");
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
```
|
|
44
|
+
## Conexion a la base de datos
|
|
45
|
+
### MYSQL
|
|
47
46
|
```ts
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
database: "pruebamaster",
|
|
52
|
-
user: "root",
|
|
47
|
+
const conexionMysql: connecionLocal = {
|
|
48
|
+
database: "pruebas",
|
|
49
|
+
host: "localhost",
|
|
53
50
|
password: "",
|
|
54
51
|
port: 3306,
|
|
55
|
-
|
|
52
|
+
user: "root",
|
|
56
53
|
};
|
|
57
54
|
|
|
58
|
-
getConexion("mysql",
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
---
|
|
55
|
+
getConexion("mysql", conexionMysql);
|
|
62
56
|
|
|
63
|
-
|
|
57
|
+
```
|
|
64
58
|
|
|
59
|
+
### PG
|
|
65
60
|
```ts
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
//Conexion por red , aqui solo se pone la ruta que por defecto te arroja la base de datos de la nube
|
|
62
|
+
const conexion2:connecionRed = {
|
|
63
|
+
connectionString:"direccion"
|
|
68
64
|
}
|
|
69
|
-
getConexion("pg",conexionPg);
|
|
70
|
-
```
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
## Métodos disponibles
|
|
75
|
-
|
|
76
|
-
### **Select**
|
|
77
|
-
### **Insert**
|
|
78
|
-
### **Update**
|
|
79
|
-
### **Delete**
|
|
80
65
|
|
|
66
|
+
const conexion: connecionLocal = {
|
|
67
|
+
database: "pruebamaster",
|
|
68
|
+
host: "localhost",
|
|
69
|
+
password: "zainmaster123",
|
|
70
|
+
port: 5432,
|
|
71
|
+
user: "postgres",
|
|
72
|
+
};
|
|
81
73
|
|
|
82
|
-
|
|
74
|
+
getConexion("pg", conexion);
|
|
83
75
|
|
|
84
|
-
|
|
76
|
+
```
|
|
85
77
|
|
|
86
|
-
|
|
78
|
+
## Definicion de Tablas
|
|
87
79
|
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
```ts
|
|
81
|
+
export const prueba1 = defineTable("prueba1", {
|
|
82
|
+
id: int().Pk().$(),
|
|
83
|
+
valor: varchar(200).Default("hola").$(),
|
|
84
|
+
resultado: int().Default(0).$(),
|
|
85
|
+
fechaRegistro: timestamp().required().now().$(),
|
|
86
|
+
fechaUpdate: timestamp().required().now().onUpdate().$()
|
|
90
87
|
|
|
91
|
-
|
|
88
|
+
});
|
|
92
89
|
|
|
90
|
+
```
|
|
93
91
|
|
|
94
|
-
###
|
|
92
|
+
### Notas importantes
|
|
93
|
+
* **.pk()** define la columna como clave primaria
|
|
94
|
+
* **.Default()** entrega un valor por defecto
|
|
95
|
+
* **.$()** finaliza la definicion y entrega un valor compatible con *$columns*
|
|
95
96
|
|
|
97
|
+
## Generacion de tablas
|
|
96
98
|
```ts
|
|
97
|
-
|
|
98
|
-
id: { typo: "int", id: true },
|
|
99
|
-
|
|
100
|
-
nombre: {
|
|
101
|
-
typo: "varchar",
|
|
102
|
-
maxLength: 200,
|
|
103
|
-
default: "hola"
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
data: {
|
|
107
|
-
typo: "varchar",
|
|
108
|
-
default: "none magic"
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
edad: {
|
|
112
|
-
typo: "int",
|
|
113
|
-
default:19
|
|
114
|
-
}
|
|
115
|
-
});
|
|
99
|
+
generateTable(prueba1(), prueba1.$columns);
|
|
116
100
|
```
|
|
117
|
-
|
|
118
|
-
### Notas
|
|
119
|
-
|
|
120
|
-
* `defineTable` registra el nombre de la tabla y sus columnas
|
|
121
|
-
* Cada propiedad representa una columna
|
|
122
|
-
* El objetivo actual es **autocompletado y estructura**, no migraciones complejas
|
|
123
|
-
* El sistema está en evolución 😢
|
|
101
|
+
Esto crea la tabla en la base de datos respetando tipos, claves primarias y valores por defecto.
|
|
124
102
|
|
|
125
103
|
---
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* $columns : es un parametro que por defecto se obtiene al definir la tabla, este reserva gran parte de los datos.
|
|
104
|
+
|
|
105
|
+
## Insertar Datos
|
|
129
106
|
|
|
130
107
|
```ts
|
|
131
|
-
|
|
132
|
-
|
|
108
|
+
await DB.Insert(prueba1(), [prueba1.valor, prueba1.resultado])
|
|
109
|
+
.Values([["hola mundo", 1], ["prueba", 0]])
|
|
110
|
+
.execute();
|
|
133
111
|
|
|
134
112
|
```
|
|
113
|
+
---
|
|
135
114
|
|
|
136
|
-
##
|
|
115
|
+
## Select de Datos
|
|
137
116
|
|
|
138
117
|
```ts
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
118
|
+
const datos = await DB.select()
|
|
119
|
+
.from(prueba1())
|
|
120
|
+
.where(eq(prueba1.id, 1))
|
|
121
|
+
.execute();
|
|
142
122
|
|
|
143
|
-
Resultado esperado:
|
|
144
|
-
|
|
145
|
-
```sql
|
|
146
|
-
INSERT INTO datosPrueba (nombre, data) VALUES (?, ?);
|
|
147
123
|
```
|
|
148
|
-
|
|
149
124
|
---
|
|
150
125
|
|
|
151
|
-
##
|
|
152
|
-
|
|
126
|
+
## Update de Datos
|
|
153
127
|
```ts
|
|
154
|
-
|
|
155
|
-
|
|
128
|
+
await DB.Update(prueba1())
|
|
129
|
+
.set({ valor: "nuevo valor", resultado: 2 })
|
|
130
|
+
.where(eq(prueba1.id, 1))
|
|
131
|
+
.execute();
|
|
132
|
+
|
|
156
133
|
```
|
|
157
134
|
---
|
|
158
|
-
|
|
159
|
-
## Ejemplo: Insert
|
|
160
|
-
|
|
135
|
+
## Delete de Datos
|
|
161
136
|
```ts
|
|
162
|
-
|
|
163
|
-
|
|
137
|
+
await DB.Delete(prueba1())
|
|
138
|
+
.where(ORQ(prueba1.id, 2, 3))
|
|
139
|
+
.execute();
|
|
140
|
+
|
|
164
141
|
```
|
|
142
|
+
|
|
165
143
|
---
|
|
166
144
|
|
|
167
|
-
##
|
|
145
|
+
## Ejemplo de Uso
|
|
168
146
|
|
|
169
147
|
```ts
|
|
170
|
-
import { connecionLocal, DB, eq,
|
|
148
|
+
import { connecionLocal, getConexion, defineTable, generateTable, int, varchar, DB, eq, ORQ } from "zormz";
|
|
171
149
|
|
|
172
150
|
const conexion: connecionLocal = {
|
|
173
151
|
database: "pruebamaster",
|
|
174
|
-
user: "root",
|
|
175
|
-
password: "",
|
|
176
|
-
port: 3306,
|
|
177
152
|
host: "localhost",
|
|
153
|
+
password: "pgZORMZ",
|
|
154
|
+
port: 5432,
|
|
155
|
+
user: "postgres",
|
|
178
156
|
};
|
|
179
157
|
|
|
180
|
-
getConexion("
|
|
158
|
+
getConexion("pg", conexion);
|
|
181
159
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
160
|
+
const prueba1 = defineTable("prueba1", {
|
|
161
|
+
id: int().Pk().$(),
|
|
162
|
+
valor: varchar(200).Default("hola").$(),
|
|
163
|
+
resultado: int().Default(0).$()
|
|
164
|
+
});
|
|
185
165
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
])
|
|
166
|
+
generateTable(prueba1(), prueba1.$columns);
|
|
167
|
+
|
|
168
|
+
async function pruebaData() {
|
|
169
|
+
await DB.Insert(prueba1(), [prueba1.valor, prueba1.resultado])
|
|
170
|
+
.Values([["hola mundo", 1], ["prueba", 0]])
|
|
191
171
|
.execute();
|
|
192
|
-
console.log(response);
|
|
193
172
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
173
|
+
const datos = await DB.select().from(prueba1()).execute();
|
|
174
|
+
console.log(datos);
|
|
175
|
+
|
|
176
|
+
await DB.Update(prueba1())
|
|
177
|
+
.set({ valor: "actualizado", resultado: 2 })
|
|
178
|
+
.where(eq(prueba1.id, 1))
|
|
197
179
|
.execute();
|
|
198
|
-
console.log(update);
|
|
199
180
|
|
|
200
|
-
|
|
201
|
-
.where(ORQ(
|
|
181
|
+
await DB.Delete(prueba1())
|
|
182
|
+
.where(ORQ(prueba1.id, 2, 3))
|
|
202
183
|
.execute();
|
|
203
|
-
console.log(eliminados);
|
|
204
184
|
}
|
|
205
185
|
|
|
206
|
-
pruebaData().catch(
|
|
207
|
-
console.log("error al cargar los datos");
|
|
208
|
-
});
|
|
186
|
+
pruebaData().catch(console.error);
|
|
209
187
|
|
|
210
188
|
```
|
|
211
189
|
|
|
212
190
|
---
|
|
213
191
|
|
|
214
|
-
##
|
|
215
|
-
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
|
|
192
|
+
## Notas
|
|
193
|
+
* ORM en version inicial con enfoque de tipado y autompletado
|
|
194
|
+
* Compatible con **MYSQL** y **PG**
|
|
195
|
+
* Preparado para extenderse
|
|
222
196
|
|
|
223
|
-
##
|
|
197
|
+
## Licencia
|
|
224
198
|
|
|
225
199
|
ISC © Yukio-kayaba
|
|
226
200
|
|
|
227
|
-
[](https://github.com/yukio-kayaba/)
|
package/package.json
CHANGED