@mostajs/orm 1.0.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/LICENSE +21 -0
- package/README.md +548 -0
- package/dist/core/base-repository.d.ts +26 -0
- package/dist/core/base-repository.js +82 -0
- package/dist/core/config.d.ts +62 -0
- package/dist/core/config.js +116 -0
- package/dist/core/errors.d.ts +30 -0
- package/dist/core/errors.js +49 -0
- package/dist/core/factory.d.ts +41 -0
- package/dist/core/factory.js +142 -0
- package/dist/core/normalizer.d.ts +9 -0
- package/dist/core/normalizer.js +19 -0
- package/dist/core/registry.d.ts +43 -0
- package/dist/core/registry.js +78 -0
- package/dist/core/types.d.ts +228 -0
- package/dist/core/types.js +5 -0
- package/dist/dialects/abstract-sql.dialect.d.ts +113 -0
- package/dist/dialects/abstract-sql.dialect.js +1071 -0
- package/dist/dialects/cockroachdb.dialect.d.ts +2 -0
- package/dist/dialects/cockroachdb.dialect.js +23 -0
- package/dist/dialects/db2.dialect.d.ts +2 -0
- package/dist/dialects/db2.dialect.js +190 -0
- package/dist/dialects/hana.dialect.d.ts +2 -0
- package/dist/dialects/hana.dialect.js +199 -0
- package/dist/dialects/hsqldb.dialect.d.ts +2 -0
- package/dist/dialects/hsqldb.dialect.js +114 -0
- package/dist/dialects/mariadb.dialect.d.ts +2 -0
- package/dist/dialects/mariadb.dialect.js +87 -0
- package/dist/dialects/mongo.dialect.d.ts +2 -0
- package/dist/dialects/mongo.dialect.js +480 -0
- package/dist/dialects/mssql.dialect.d.ts +27 -0
- package/dist/dialects/mssql.dialect.js +127 -0
- package/dist/dialects/mysql.dialect.d.ts +24 -0
- package/dist/dialects/mysql.dialect.js +101 -0
- package/dist/dialects/oracle.dialect.d.ts +2 -0
- package/dist/dialects/oracle.dialect.js +206 -0
- package/dist/dialects/postgres.dialect.d.ts +26 -0
- package/dist/dialects/postgres.dialect.js +105 -0
- package/dist/dialects/spanner.dialect.d.ts +2 -0
- package/dist/dialects/spanner.dialect.js +259 -0
- package/dist/dialects/sqlite.dialect.d.ts +2 -0
- package/dist/dialects/sqlite.dialect.js +1027 -0
- package/dist/dialects/sybase.dialect.d.ts +2 -0
- package/dist/dialects/sybase.dialect.js +119 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +26 -0
- package/docs/api-reference.md +1009 -0
- package/docs/dialects.md +673 -0
- package/docs/tutorial.md +846 -0
- package/package.json +91 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Sybase ASE Dialect — extends MSSQLDialect
|
|
2
|
+
// Equivalent to org.hibernate.dialect.SybaseASEDialect (Hibernate ORM 6.4)
|
|
3
|
+
// Sybase ASE shares T-SQL heritage with SQL Server
|
|
4
|
+
// Driver: npm install sybase
|
|
5
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
6
|
+
import { MSSQLDialect } from './mssql.dialect.js';
|
|
7
|
+
// ============================================================
|
|
8
|
+
// Sybase Type Mapping overrides
|
|
9
|
+
// ============================================================
|
|
10
|
+
const SYBASE_TYPE_MAP = {
|
|
11
|
+
string: 'NVARCHAR(MAX)',
|
|
12
|
+
number: 'FLOAT',
|
|
13
|
+
boolean: 'TINYINT',
|
|
14
|
+
date: 'DATETIME',
|
|
15
|
+
json: 'TEXT',
|
|
16
|
+
array: 'TEXT',
|
|
17
|
+
};
|
|
18
|
+
// ============================================================
|
|
19
|
+
// SybaseDialect
|
|
20
|
+
// ============================================================
|
|
21
|
+
class SybaseDialect extends MSSQLDialect {
|
|
22
|
+
dialectType = 'sybase';
|
|
23
|
+
// Sybase ASE does NOT support RETURNING/OUTPUT
|
|
24
|
+
supportsReturning() { return false; }
|
|
25
|
+
// Sybase uses TINYINT for boolean (not BIT)
|
|
26
|
+
serializeBoolean(v) { return v ? 1 : 0; }
|
|
27
|
+
deserializeBoolean(v) {
|
|
28
|
+
return v === 1 || v === true || v === '1';
|
|
29
|
+
}
|
|
30
|
+
// Override type mapping for Sybase-specific types
|
|
31
|
+
fieldToSqlType(field) {
|
|
32
|
+
return SYBASE_TYPE_MAP[field.type] || 'NVARCHAR(MAX)';
|
|
33
|
+
}
|
|
34
|
+
getTableListQuery() {
|
|
35
|
+
return "SELECT name FROM sysobjects WHERE type = 'U'";
|
|
36
|
+
}
|
|
37
|
+
// Sybase uses TOP n instead of OFFSET/FETCH
|
|
38
|
+
buildLimitOffset(options) {
|
|
39
|
+
// Sybase doesn't support OFFSET/FETCH
|
|
40
|
+
// TOP is applied in the SELECT clause — handled differently
|
|
41
|
+
// For now return empty; TOP is handled via query rewrite
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
// Override connection to use sybase driver
|
|
45
|
+
async doConnect(config) {
|
|
46
|
+
try {
|
|
47
|
+
const sybase = await import(/* webpackIgnore: true */ 'sybase');
|
|
48
|
+
const SybaseDriver = sybase.default || sybase;
|
|
49
|
+
const parsed = this.parseSybaseUri(config.uri);
|
|
50
|
+
this.pool = new SybaseDriver(parsed);
|
|
51
|
+
await this.pool.connect();
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
throw new Error(`Sybase driver not found. Install it: npm install sybase\n` +
|
|
55
|
+
`Original error: ${e instanceof Error ? e.message : String(e)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async doDisconnect() {
|
|
59
|
+
if (this.pool) {
|
|
60
|
+
await this.pool.disconnect();
|
|
61
|
+
this.pool = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async doTestConnection() {
|
|
65
|
+
if (!this.pool)
|
|
66
|
+
return false;
|
|
67
|
+
await this.pool.query('SELECT 1');
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
async executeQuery(sql, params) {
|
|
71
|
+
if (!this.pool)
|
|
72
|
+
throw new Error('Sybase not connected. Call connect() first.');
|
|
73
|
+
// Sybase driver doesn't support named params — replace @pN with values
|
|
74
|
+
const resolvedSql = this.resolveParams(sql, params);
|
|
75
|
+
const result = await this.pool.query(resolvedSql);
|
|
76
|
+
return Array.isArray(result) ? result : [];
|
|
77
|
+
}
|
|
78
|
+
async executeRun(sql, params) {
|
|
79
|
+
if (!this.pool)
|
|
80
|
+
throw new Error('Sybase not connected. Call connect() first.');
|
|
81
|
+
const resolvedSql = this.resolveParams(sql, params);
|
|
82
|
+
const result = await this.pool.query(resolvedSql);
|
|
83
|
+
return { changes: result?.rowsAffected ?? 0 };
|
|
84
|
+
}
|
|
85
|
+
/** Inline parameters into SQL (Sybase driver limitation) */
|
|
86
|
+
resolveParams(sql, params) {
|
|
87
|
+
let result = sql;
|
|
88
|
+
for (let i = params.length; i >= 1; i--) {
|
|
89
|
+
const val = params[i - 1];
|
|
90
|
+
const replacement = val === null ? 'NULL'
|
|
91
|
+
: typeof val === 'number' ? String(val)
|
|
92
|
+
: `'${String(val).replace(/'/g, "''")}'`;
|
|
93
|
+
result = result.replace(`@p${i}`, replacement);
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
parseSybaseUri(uri) {
|
|
98
|
+
try {
|
|
99
|
+
const url = new URL(uri.replace(/^sybase:/, 'http:'));
|
|
100
|
+
return {
|
|
101
|
+
host: url.hostname || 'localhost',
|
|
102
|
+
port: url.port ? parseInt(url.port) : 5000,
|
|
103
|
+
user: url.username || 'sa',
|
|
104
|
+
password: url.password || '',
|
|
105
|
+
database: url.pathname.replace(/^\//, '') || 'master',
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return { host: 'localhost', port: 5000, database: 'master' };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
getDialectLabel() { return 'Sybase'; }
|
|
113
|
+
}
|
|
114
|
+
// ============================================================
|
|
115
|
+
// Factory export
|
|
116
|
+
// ============================================================
|
|
117
|
+
export function createDialect() {
|
|
118
|
+
return new SybaseDialect();
|
|
119
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { FieldType, FieldDef, EmbeddedSchemaDef, RelationType, RelationDef, IndexType, IndexDef, EntitySchema, FilterOperator, FilterValue, FilterQuery, SortDirection, QueryOptions, PaginatedResult, AggregateStage, AggregateGroupStage, AggregateMatchStage, AggregateSortStage, AggregateLimitStage, AggregateAccumulator, DialectType, SchemaStrategy, ConnectionConfig, IDialect, IRepository, IPlugin, HookContext, NormalizedDoc, } from './core/types.js';
|
|
2
|
+
export { DIALECT_CONFIGS, getSupportedDialects, getDialectConfig, } from './core/config.js';
|
|
3
|
+
export type { DialectConfig } from './core/config.js';
|
|
4
|
+
export { registerSchema, registerSchemas, getSchema, getSchemaByCollection, getAllSchemas, getEntityNames, hasSchema, validateSchemas, clearRegistry, } from './core/registry.js';
|
|
5
|
+
export { getDialect, getConfigFromEnv, getCurrentDialectType, disconnectDialect, testConnection, createConnection, } from './core/factory.js';
|
|
6
|
+
export { BaseRepository } from './core/base-repository.js';
|
|
7
|
+
export { normalizeDoc, normalizeDocs } from './core/normalizer.js';
|
|
8
|
+
export { MostaORMError, EntityNotFoundError, ConnectionError, ValidationError, DialectNotFoundError, } from './core/errors.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// MostaORM — Hibernate-inspired multi-dialect ORM for Node.js/TypeScript
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
// ============================================================
|
|
4
|
+
// Config
|
|
5
|
+
// ============================================================
|
|
6
|
+
export { DIALECT_CONFIGS, getSupportedDialects, getDialectConfig, } from './core/config.js';
|
|
7
|
+
// ============================================================
|
|
8
|
+
// Registry
|
|
9
|
+
// ============================================================
|
|
10
|
+
export { registerSchema, registerSchemas, getSchema, getSchemaByCollection, getAllSchemas, getEntityNames, hasSchema, validateSchemas, clearRegistry, } from './core/registry.js';
|
|
11
|
+
// ============================================================
|
|
12
|
+
// Factory
|
|
13
|
+
// ============================================================
|
|
14
|
+
export { getDialect, getConfigFromEnv, getCurrentDialectType, disconnectDialect, testConnection, createConnection, } from './core/factory.js';
|
|
15
|
+
// ============================================================
|
|
16
|
+
// Base Repository
|
|
17
|
+
// ============================================================
|
|
18
|
+
export { BaseRepository } from './core/base-repository.js';
|
|
19
|
+
// ============================================================
|
|
20
|
+
// Utils
|
|
21
|
+
// ============================================================
|
|
22
|
+
export { normalizeDoc, normalizeDocs } from './core/normalizer.js';
|
|
23
|
+
// ============================================================
|
|
24
|
+
// Errors
|
|
25
|
+
// ============================================================
|
|
26
|
+
export { MostaORMError, EntityNotFoundError, ConnectionError, ValidationError, DialectNotFoundError, } from './core/errors.js';
|