@hemia/db-connector 0.0.7 → 0.0.9

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 CHANGED
@@ -17,9 +17,11 @@ npm install @hemia/db-connector
17
17
  ### 🗄️ SQL (OLTP - Online Transaction Processing)
18
18
  Bases de datos relacionales optimizadas para transacciones y operaciones CRUD.
19
19
 
20
- * ✅ **MySQL** - Base de datos relacional de código abierto
20
+ * ✅ **MySQL** - Base de datos relacional de código abierto (Sequelize)
21
21
  * ✅ **PostgreSQL** - Base de datos relacional avanzada con soporte JSON
22
- * **Microsoft SQL Server (MSSQL)** - Base de datos empresarial de Microsoft
22
+ - **Sequelize** - ORM tradicional
23
+ - **Drizzle ORM** - ORM moderno con TypeScript nativo y máximo rendimiento
24
+ * ✅ **Microsoft SQL Server (MSSQL)** - Base de datos empresarial de Microsoft (Sequelize)
23
25
 
24
26
  **Casos de uso:**
25
27
  - Sistemas transaccionales (e-commerce, banking)
@@ -102,6 +104,96 @@ await sql.withTransaction(async (transaction) => {
102
104
  });
103
105
  ```
104
106
 
107
+ ### PostgreSQL con Drizzle ORM (Recomendado)
108
+
109
+ ```ts
110
+ import {
111
+ DrizzlePostgresConnector,
112
+ pgTable,
113
+ serial,
114
+ varchar,
115
+ integer,
116
+ eq,
117
+ and,
118
+ gt
119
+ } from '@hemia/db-connector';
120
+
121
+ // 1. Definir schema con tipos
122
+ const users = pgTable('users', {
123
+ id: serial('id').primaryKey(),
124
+ name: varchar('name', { length: 255 }).notNull(),
125
+ email: varchar('email', { length: 255 }).notNull().unique(),
126
+ age: integer('age')
127
+ });
128
+
129
+ // 2. Conectar y registrar schema
130
+ const connector = new DrizzlePostgresConnector({
131
+ host: 'localhost',
132
+ port: 5432,
133
+ database: 'mydb',
134
+ user: 'postgres',
135
+ password: 'password',
136
+ dialect: 'postgresql'
137
+ });
138
+
139
+ await connector.connect();
140
+ connector.registerTableSchema('users', users);
141
+
142
+ // 3. Usar API nativa de Drizzle (tipado completo)
143
+ const db = connector.getDb();
144
+
145
+ // SELECT con tipos inferidos
146
+ const activeAdults = await db
147
+ .select()
148
+ .from(users)
149
+ .where(and(
150
+ eq(users.status, 'active'),
151
+ gt(users.age, 18)
152
+ ));
153
+
154
+ // INSERT con autocompletado
155
+ const newUser = await db
156
+ .insert(users)
157
+ .values({
158
+ name: 'John Doe',
159
+ email: 'john@example.com',
160
+ age: 30
161
+ })
162
+ .returning();
163
+
164
+ // UPDATE
165
+ await db
166
+ .update(users)
167
+ .set({ name: 'Jane Doe' })
168
+ .where(eq(users.id, 1));
169
+
170
+ // O usar API abstracta (compatible con Sequelize)
171
+ const users = await connector.select('users', {
172
+ where: { age: { $gt: 18 } },
173
+ limit: 10
174
+ });
175
+ ```
176
+
177
+ **Operadores soportados:**
178
+ - `eq(column, value)` - Igual a
179
+ - `ne(column, value)` - No igual a
180
+ - `gt(column, value)` - Mayor que / `gte` - Mayor o igual
181
+ - `lt(column, value)` - Menor que / `lte` - Menor o igual
182
+ - `like(column, pattern)` - LIKE / `ilike` - ILIKE (case-insensitive)
183
+ - `inArray(column, values)` - IN (lista)
184
+ - `isNull(column)` - IS NULL
185
+ - `and(...conditions)` - AND lógico / `or` - OR lógico
186
+ - `not(condition)` - NOT lógico
187
+
188
+ **Ventajas de Drizzle sobre Sequelize:**
189
+ - ⚡ **3-4x más rápido** en queries complejas
190
+ - 🎯 **Type-safety 100%** sin decoradores ni boilerplate
191
+ - 📦 **Bundle 50% más pequeño** que Sequelize
192
+ - 🔧 **Migrations automáticas** con Drizzle Kit
193
+ - 🚀 **Zero overhead** - todo compile-time
194
+
195
+ > 📖 **Nota técnica**: DrizzlePostgresConnector usa una arquitectura independiente (`DrizzleSqlConnector`) sin dependencias de Sequelize. Ver [DRIZZLE_REFACTOR.md](./DRIZZLE_REFACTOR.md) para detalles de implementación.
196
+
105
197
  ### ClickHouse (OLAP)
106
198
 
107
199
  ```ts