Skip to content

Commit

Permalink
feature(sql): remove pg-native to make deployment easier
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Oct 5, 2023
1 parent 852da12 commit 1495723
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 22 deletions.
77 changes: 62 additions & 15 deletions packages/postgres/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"dependencies": {
"@types/pg": "^7.14.7",
"pg": "^8.5.1",
"pg-native": "^3.0.0",
"sqlstring": "^2.3.2"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions packages/sql/src/platform/default-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export abstract class DefaultPlatform {
}, sqlType, size, scale);
}

/**
* Last matching check wins.
*/
addType(kind: ReflectionKind | TypeMappingChecker, sqlType: string, size?: number, scale?: number, unsigned?: boolean) {
this.typeMapping.set(kind, { sqlType, size, scale, unsigned });
}
Expand Down
1 change: 0 additions & 1 deletion packages/sql/src/serializer/sql-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ function deserializeSqlArray(type: TypeArray, state: TemplateState) {
*/
function serializeSqlObjectLiteral(type: TypeClass | TypeObjectLiteral, state: TemplateState) {
if (undefined !== referenceAnnotation.getFirst(type)) return;

if (!isDirectPropertyOfEntity(type)) return;

//TypeClass|TypeObjectLiteral properties are serialized as JSON
Expand Down
13 changes: 8 additions & 5 deletions packages/sql/src/sql-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
FilterQuery,
FindQuery,
GenericQueryResolver,
ItemNotFound, MigrateOptions,
ItemNotFound,
MigrateOptions,
OrmEntity,
PatchResult,
Query,
Expand All @@ -45,6 +46,7 @@ import {
ReceiveType,
ReflectionClass,
ReflectionKind,
ReflectionProperty,
resolveReceiveType,
Type
} from '@deepkit/type';
Expand Down Expand Up @@ -822,7 +824,7 @@ export class SQLPersistence extends DatabasePersistence {

const v = converted[property.name];
params.push(v === undefined ? null : v);
row.push(this.getPlaceholderSymbol());
row.push(this.getPlaceholderSymbol(property));
}

insert.push(row.join(', '));
Expand All @@ -842,7 +844,7 @@ export class SQLPersistence extends DatabasePersistence {
protected resetPlaceholderSymbol() {
}

protected getPlaceholderSymbol() {
protected getPlaceholderSymbol(property: ReflectionProperty) {
return '?';
}

Expand All @@ -854,12 +856,13 @@ export class SQLPersistence extends DatabasePersistence {
async remove<T extends OrmEntity>(classSchema: ReflectionClass<T>, items: T[]): Promise<void> {
const scopeSerializer = getSerializeFunction(classSchema.type, this.platform.serializer.serializeRegistry);
const pks: any[] = [];
const pkName = classSchema.getPrimary().name;
const primary = classSchema.getPrimary();
const pkName = primary.name;
const params: any[] = [];

for (const item of items) {
const converted = scopeSerializer(item);
pks.push(this.getPlaceholderSymbol());
pks.push(this.getPlaceholderSymbol(primary));
params.push(converted[pkName]);
}

Expand Down

0 comments on commit 1495723

Please sign in to comment.