zormz 1.0.0 → 1.1.0
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 +197 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,197 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# ZORMZ
|
|
2
|
+
|
|
3
|
+
Un ORM ligero escrito en TypeScript para MySQL y PostgreSQL, diseñado para ser simple, rápido y extensible.
|
|
4
|
+
por ahora solo es posible conectarse a una base de datos.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Características
|
|
9
|
+
|
|
10
|
+
* Compatible con **ESM** y **CommonJS**
|
|
11
|
+
* Tipado completo en **TypeScript**
|
|
12
|
+
* Builder con sintaxis encadenada: `select().from().where().execute()`
|
|
13
|
+
* Insert múltiple con arrays
|
|
14
|
+
* Soporte para MySQL y PostgreSQL
|
|
15
|
+
* Sin dependencias pesadas
|
|
16
|
+
* Fácil de extender
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Instalación
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install zormz
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Uso básico
|
|
29
|
+
|
|
30
|
+
### Importación (ESM)
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { connecionLocal, getConexion } from "zormz";
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Importación (CommonJS)
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const { connecionLocal, getConexion } = require("zormz");
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Ejemplo: Insertar datos
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const response = await DB.Insert('datosPrueba',
|
|
48
|
+
['nombre', 'data']).Values(['yunno','magic wind']).execute();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Resultado esperado:
|
|
52
|
+
|
|
53
|
+
```sql
|
|
54
|
+
INSERT INTO datosPrueba (nombre, data) VALUES (?, ?);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Ejemplo: Select
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
let datos = await DB.select().from("datosPrueba").execute();
|
|
63
|
+
console.log(datos);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Conexión a la base de datos
|
|
69
|
+
### mysql local
|
|
70
|
+
```ts
|
|
71
|
+
import { connecionLocal, DB, getConexion } from "zormz";
|
|
72
|
+
//de preferencia esto en el archivo raiz index.ts
|
|
73
|
+
const conexion: connecionLocal = {
|
|
74
|
+
database: "pruebamaster",
|
|
75
|
+
user: "root",
|
|
76
|
+
password: "",
|
|
77
|
+
port: 3306,
|
|
78
|
+
host: "localhost",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
getConexion("mysql", conexion);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### pg en linea
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const conexionPg:connecionRed = {
|
|
90
|
+
connectionString:"ruta de la conexion"
|
|
91
|
+
}
|
|
92
|
+
getConexion("pg",conexionPg);
|
|
93
|
+
```
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Definir tablas para uso dev
|
|
97
|
+
* Puede exportarse como una constante para programarlo y guiarnos facilmente
|
|
98
|
+
### defineTable
|
|
99
|
+
* `export const productosPrueba = defineTable("productosPrueba",{`
|
|
100
|
+
* `id:"id",`
|
|
101
|
+
* `nombre:"nombre",`
|
|
102
|
+
* `descripcion:"descripcion"`
|
|
103
|
+
* `});`
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Ejemplo: definicion de tabla
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const response = await DB.Insert(productosPrueba(),
|
|
110
|
+
[productosPrueba.nombre,productosPrueba.descripcion]).Values(['yunno','magic wind']).execute();
|
|
111
|
+
```
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Métodos disponibles
|
|
115
|
+
|
|
116
|
+
### **Select**
|
|
117
|
+
|
|
118
|
+
* `DB.select(campos)`
|
|
119
|
+
* `.from(tabla)`
|
|
120
|
+
* `.where(condición, valores).execute()`
|
|
121
|
+
|
|
122
|
+
### **Insert**
|
|
123
|
+
|
|
124
|
+
* `DB.Insert(campos)`
|
|
125
|
+
* `.valores(arrayDeValores).execute()`
|
|
126
|
+
|
|
127
|
+
### **Update**
|
|
128
|
+
|
|
129
|
+
* `DB.update(tabla)`
|
|
130
|
+
* `.set(campos).execute()`
|
|
131
|
+
|
|
132
|
+
### **Delete**
|
|
133
|
+
|
|
134
|
+
* `DB.deleteFrom(tabla).where(condicionales).execute()`
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
## Ejemplo completo
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { connecionLocal, DB, eq, getConexion, ORQ } from "zormz";
|
|
141
|
+
|
|
142
|
+
const conexion: connecionLocal = {
|
|
143
|
+
database: "pruebamaster",
|
|
144
|
+
user: "root",
|
|
145
|
+
password: "",
|
|
146
|
+
port: 3306,
|
|
147
|
+
host: "localhost",
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
getConexion("mysql", conexion);
|
|
151
|
+
|
|
152
|
+
async function pruebaData() {
|
|
153
|
+
let datos = await DB.select().from("datosPrueba").execute();
|
|
154
|
+
console.log(datos);
|
|
155
|
+
|
|
156
|
+
let response = await DB.Insert("datosPrueba", ["nombre", "data"])
|
|
157
|
+
.Values([
|
|
158
|
+
["yunno", "magic wind"],
|
|
159
|
+
["astta", "no magic"],
|
|
160
|
+
])
|
|
161
|
+
.execute();
|
|
162
|
+
console.log(response);
|
|
163
|
+
|
|
164
|
+
let update = await DB.update("datosPrueba")
|
|
165
|
+
.set({ nombre: "yukio", data: "es un juego ?" })
|
|
166
|
+
.where(eq("id", 1))
|
|
167
|
+
.execute();
|
|
168
|
+
console.log(update);
|
|
169
|
+
|
|
170
|
+
let eliminados = await DB.Delete("datosPrueba")
|
|
171
|
+
.where(ORQ("id", 3, 4, 5, 6))
|
|
172
|
+
.execute();
|
|
173
|
+
console.log(eliminados);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
pruebaData().catch((e) => {
|
|
177
|
+
console.log("error al cargar los datos");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 📝 Notas
|
|
185
|
+
|
|
186
|
+
* Este ORM está en versión inicial.
|
|
187
|
+
* Puedes extenderlo o contribuir con nuevas funciones.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
## 📄 Licencia
|
|
194
|
+
|
|
195
|
+
ISC © Yukio-kayaba
|
|
196
|
+
|
|
197
|
+
[](https://github.com/yukio-kayaba/)
|