Comparing version 1.0.257 to 1.0.258
@@ -35,2 +35,3 @@ "use strict"; | ||
await (0, mutate_1.orma_mutate)(Object.assign({ $operation: 'create' }, hydration_data), (0, database_adapters_1.sqlite3_adapter)(db), orma_schema); | ||
await (0, database_adapters_1.sqlite3_adapter)(db)([{ sql_string: 'PRAGMA foreign_keys = ON' }]); | ||
(0, fs_1.copyFileSync)(get_db_path(directory_path), get_checkpoint_path(directory_path)); | ||
@@ -37,0 +38,0 @@ return db; |
@@ -1,2 +0,2 @@ | ||
import { OrmaSchema } from '../../types/schema/schema_types'; | ||
import { OrmaSchema, SupportedDatabases } from '../../types/schema/schema_types'; | ||
import { Path } from '../../types'; | ||
@@ -14,3 +14,3 @@ import { operation } from '../mutate'; | ||
}; | ||
export declare const generate_statement: (ast: Record<string, any>, mutation_pieces: MutationPiece[], mutation_piece_indices: number[]) => OrmaStatement; | ||
export declare const generate_statement: (ast: Record<string, any>, mutation_pieces: MutationPiece[], mutation_piece_indices: number[], database_type: SupportedDatabases) => OrmaStatement; | ||
export type OrmaStatement = { | ||
@@ -17,0 +17,0 @@ ast: Record<string, any>; |
@@ -31,5 +31,6 @@ "use strict"; | ||
const guid_query = (0, mutation_guid_query_1.get_guid_query)(mutation_pieces, group_indices, entity, guid_map, orma_schema); | ||
const database_type = orma_schema.$entities[entity].$database_type; | ||
return guid_query | ||
? [ | ||
(0, exports.generate_statement)(guid_query, mutation_pieces, group_indices) | ||
(0, exports.generate_statement)(guid_query, mutation_pieces, group_indices, database_type) | ||
] | ||
@@ -68,2 +69,3 @@ : []; | ||
} | ||
const database_type = orma_schema.$entities[entity].$database_type; | ||
return asts.flatMap(ast => | ||
@@ -73,5 +75,7 @@ // can be undefined if there is nothing to do, e.g. a stub update | ||
? [] | ||
: [(0, exports.generate_statement)(ast, mutation_pieces, mutation_piece_indices)]); | ||
: [ | ||
(0, exports.generate_statement)(ast, mutation_pieces, mutation_piece_indices, database_type) | ||
]); | ||
}; | ||
const generate_statement = (ast, mutation_pieces, mutation_piece_indices) => { | ||
const generate_statement = (ast, mutation_pieces, mutation_piece_indices, database_type) => { | ||
var _a, _b, _c, _d; | ||
@@ -85,3 +89,3 @@ const first_piece = mutation_pieces[mutation_piece_indices[0]]; | ||
records: (_d = mutation_piece_indices === null || mutation_piece_indices === void 0 ? void 0 : mutation_piece_indices.map(i => mutation_pieces[i].record)) !== null && _d !== void 0 ? _d : [], | ||
sql_string: (0, ast_to_sql_1.json_to_sql)(ast) | ||
sql_string: (0, ast_to_sql_1.json_to_sql)(ast, database_type) | ||
}; | ||
@@ -88,0 +92,0 @@ return statement; |
@@ -18,3 +18,7 @@ "use strict"; | ||
} | ||
const ownership_results = await mysql_function(ownership_queries.map(ownership_query => (0, mutation_statements_1.generate_statement)(ownership_query, [], []))); | ||
const ownership_results = await mysql_function(ownership_queries.map(ownership_query => { | ||
const entity = ownership_query.$from; | ||
const database_type = orma_schema.$entities[entity].$database_type; | ||
return (0, mutation_statements_1.generate_statement)(ownership_query, [], [], database_type); | ||
})); | ||
const errors = generate_ownership_errors(ownership_results, where_connecteds); | ||
@@ -117,3 +121,3 @@ return errors; | ||
const values = piece_indices | ||
.map((piece_index) => { | ||
.map(piece_index => { | ||
const { record } = mutation_pieces[piece_index]; | ||
@@ -120,0 +124,0 @@ const field = edge_path[0].from_field; |
@@ -227,3 +227,5 @@ "use strict"; | ||
// DML commands | ||
$select: args => `SELECT ${args.join(', ')}`, $as: args => `${wrap_if_subquery(args[0])} AS ${args[1]}`, $entity: (args, path, obj, database_type) => `${escape_field(args, database_type)}`, $field: (args, path, obj, database_type) => `.${escape_field(args, database_type)}`, $from: (args, path, obj, database_type) => `FROM ${escape_field(args, database_type)}`, $where: args => `WHERE ${args}`, $group_by: args => `GROUP BY ${args.join(', ')}`, $having: args => `HAVING ${args}`, $order_by: args => `ORDER BY ${args.join(', ')}`, $for: args => `FOR ${args}`, $share: args => `SHARE ${args}`, $of: args => `OF ${args.join(', ')}`, $no_wait: args => `NOWAIT ${args}`, $skip_locked: args => `SKIP LOCKED ${args}`, $asc: args => `${args} ASC`, $desc: args => `${args} DESC`, $limit: args => `LIMIT ${args}`, $offset: args => `OFFSET ${args}`, $in: (args, path) => { | ||
$select: args => `SELECT ${args.join(', ')}`, $as: args => `${wrap_if_subquery(args[0])} AS ${args[1]}`, $entity: (args, path, obj, database_type) => `${escape_field(args, database_type)}`, $field: (args, path, obj, database_type) => `.${escape_field(args, database_type)}`, $from: (args, path, obj, database_type) => `FROM ${escape_field(args, database_type)}`, $where: args => `WHERE ${args}`, $group_by: args => `GROUP BY ${args.join(', ')}`, $having: args => `HAVING ${args}`, $order_by: args => `ORDER BY ${args.join(', ')}`, $for: (args, path, obj, database_type) => | ||
// sqlite doesnt support SELECT ... FOR UPDATE | ||
database_type === 'sqlite' ? '' : `FOR ${args}`, $share: args => `SHARE ${args}`, $of: args => `OF ${args.join(', ')}`, $no_wait: args => `NOWAIT ${args}`, $skip_locked: args => `SKIP LOCKED ${args}`, $asc: args => `${args} ASC`, $desc: args => `${args} DESC`, $limit: args => `LIMIT ${args}`, $offset: args => `OFFSET ${args}`, $in: (args, path) => { | ||
const [left_arg, right_arg] = args; | ||
@@ -230,0 +232,0 @@ const left_arg_string = Array.isArray(left_arg) |
@@ -48,3 +48,3 @@ "use strict"; | ||
path.flatMap(path_el => [path_el, 0]), | ||
(rows === null || rows === void 0 ? void 0 : rows.length) ? rows : undefined, | ||
(rows === null || rows === void 0 ? void 0 : rows.length) ? rows : undefined | ||
]; | ||
@@ -89,3 +89,7 @@ }); | ||
const output = subquery_data.length > 0 | ||
? await query_function(subquery_data.map(({ subquery }) => (0, mutation_statements_1.generate_statement)(subquery, [], []))) | ||
? await query_function(subquery_data.map(({ subquery }) => { | ||
const entity = subquery.$from; | ||
const database_type = orma_schema.$entities[entity].$database_type; | ||
return (0, mutation_statements_1.generate_statement)(subquery, [], [], database_type); | ||
})) | ||
: []; | ||
@@ -97,3 +101,3 @@ // Combine outputs | ||
additions: subquery_data[i].nester_additions, | ||
deletions: subquery_data[i].nester_deletions, | ||
deletions: subquery_data[i].nester_deletions | ||
}); | ||
@@ -100,0 +104,0 @@ }); |
{ | ||
"name": "orma", | ||
"version": "1.0.257", | ||
"version": "1.0.258", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -51,2 +51,3 @@ import * as sqlite3 from 'sqlite3' | ||
) | ||
await sqlite3_adapter(db)([{ sql_string: 'PRAGMA foreign_keys = ON' }]) | ||
copyFileSync( | ||
@@ -53,0 +54,0 @@ get_db_path(directory_path), |
import { push_path } from '../../helpers/push_path' | ||
import { OrmaSchema } from '../../types/schema/schema_types' | ||
import { OrmaSchema, SupportedDatabases } from '../../types/schema/schema_types' | ||
import { json_to_sql } from '../../query/ast_to_sql' | ||
@@ -65,2 +65,3 @@ import { Path } from '../../types' | ||
) | ||
const database_type = orma_schema.$entities[entity].$database_type | ||
return guid_query | ||
@@ -71,3 +72,4 @@ ? [ | ||
mutation_pieces, | ||
group_indices | ||
group_indices, | ||
database_type | ||
) | ||
@@ -137,2 +139,3 @@ ] | ||
const database_type = orma_schema.$entities[entity].$database_type | ||
return asts.flatMap(ast => | ||
@@ -142,3 +145,10 @@ // can be undefined if there is nothing to do, e.g. a stub update | ||
? [] | ||
: [generate_statement(ast, mutation_pieces, mutation_piece_indices)] | ||
: [ | ||
generate_statement( | ||
ast, | ||
mutation_pieces, | ||
mutation_piece_indices, | ||
database_type | ||
) | ||
] | ||
) | ||
@@ -156,3 +166,4 @@ } | ||
mutation_pieces: MutationPiece[], | ||
mutation_piece_indices: number[] | ||
mutation_piece_indices: number[], | ||
database_type: SupportedDatabases | ||
) => { | ||
@@ -168,3 +179,3 @@ const first_piece = mutation_pieces[mutation_piece_indices[0]] | ||
mutation_piece_indices?.map(i => mutation_pieces[i].record) ?? [], | ||
sql_string: json_to_sql(ast) | ||
sql_string: json_to_sql(ast, database_type) | ||
} | ||
@@ -171,0 +182,0 @@ |
@@ -41,5 +41,7 @@ import { OrmaError } from '../../helpers/error_handling' | ||
const ownership_results = await mysql_function( | ||
ownership_queries.map(ownership_query => | ||
generate_statement(ownership_query, [], []) | ||
) | ||
ownership_queries.map(ownership_query => { | ||
const entity = ownership_query.$from | ||
const database_type = orma_schema.$entities[entity].$database_type | ||
return generate_statement(ownership_query, [], [], database_type) | ||
}) | ||
) | ||
@@ -216,3 +218,3 @@ | ||
const values = piece_indices | ||
.map((piece_index) => { | ||
.map(piece_index => { | ||
const { record } = mutation_pieces[piece_index] | ||
@@ -219,0 +221,0 @@ const field = edge_path[0].from_field |
@@ -327,3 +327,5 @@ /** | ||
$order_by: args => `ORDER BY ${args.join(', ')}`, | ||
$for: args => `FOR ${args}`, | ||
$for: (args, path, obj, database_type) => | ||
// sqlite doesnt support SELECT ... FOR UPDATE | ||
database_type === 'sqlite' ? '' : `FOR ${args}`, | ||
$share: args => `SHARE ${args}`, | ||
@@ -330,0 +332,0 @@ $of: args => `OF ${args.join(', ')}`, |
@@ -14,3 +14,3 @@ import { clone, deep_get, drop_last, last } from '../helpers/helpers' | ||
apply_nesting_macro, | ||
should_nesting_short_circuit, | ||
should_nesting_short_circuit | ||
} from './macros/nesting_macro' | ||
@@ -20,3 +20,3 @@ import { apply_select_macro } from './macros/select_macro' | ||
apply_where_connected_macro, | ||
ConnectionEdges, | ||
ConnectionEdges | ||
} from './macros/where_connected_macro' | ||
@@ -50,3 +50,3 @@ import { get_query_plan } from './query_plan' | ||
nester_modifications: NesterModification[], | ||
results: [string[], Record<string, unknown>[]][], | ||
results: [string[], Record<string, unknown>[]][] | ||
) => { | ||
@@ -81,3 +81,3 @@ // get data in the right format for the nester | ||
path.flatMap(path_el => [path_el, 0]), | ||
rows?.length ? rows : undefined, | ||
rows?.length ? rows : undefined | ||
] | ||
@@ -146,5 +146,13 @@ }) | ||
? await query_function( | ||
subquery_data.map(({ subquery }) => | ||
generate_statement(subquery, [], []) | ||
) | ||
subquery_data.map(({ subquery }) => { | ||
const entity = subquery.$from | ||
const database_type = | ||
orma_schema.$entities[entity].$database_type | ||
return generate_statement( | ||
subquery, | ||
[], | ||
[], | ||
database_type | ||
) | ||
}) | ||
) | ||
@@ -158,3 +166,3 @@ : [] | ||
additions: subquery_data[i].nester_additions, | ||
deletions: subquery_data[i].nester_deletions, | ||
deletions: subquery_data[i].nester_deletions | ||
}) | ||
@@ -161,0 +169,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1691076
41209