@@ -830,15 +830,15 @@ export class PostgresStorageAdapter implements StorageAdapter {
830
830
831
831
setClassLevelPermissions ( className : string , CLPs : any ) {
832
832
const self = this ;
833
- return this . _client . task ( 'set-class-level-permissions' , function * ( t ) {
834
- yield self . _ensureSchemaCollectionExists ( t ) ;
833
+ return this . _client . task ( 'set-class-level-permissions' , async ( t ) => {
834
+ await self . _ensureSchemaCollectionExists ( t ) ;
835
835
const values = [
836
836
className ,
837
837
'schema' ,
838
838
'classLevelPermissions' ,
839
839
JSON . stringify ( CLPs ) ,
840
840
] ;
841
- yield t . none (
841
+ await t . none (
842
842
`UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1` ,
843
843
values
844
844
) ;
@@ -895,15 +895,15 @@ export class PostgresStorageAdapter implements StorageAdapter {
895
895
} ) ;
896
896
}
897
897
} ) ;
898
- return conn . tx ( 'set-indexes-with-schema-format' , function * ( t ) {
898
+ return conn . tx ( 'set-indexes-with-schema-format' , async ( t ) => {
899
899
if ( insertedIndexes . length > 0 ) {
900
- yield self . createIndexes ( className , insertedIndexes , t ) ;
900
+ await self . createIndexes ( className , insertedIndexes , t ) ;
901
901
}
902
902
if ( deletedIndexes . length > 0 ) {
903
- yield self . dropIndexes ( className , deletedIndexes , t ) ;
903
+ await self . dropIndexes ( className , deletedIndexes , t ) ;
904
904
}
905
- yield self . _ensureSchemaCollectionExists ( t ) ;
906
- yield t . none (
905
+ await self . _ensureSchemaCollectionExists ( t ) ;
906
+ await t . none (
907
907
'UPDATE "_SCHEMA" SET $2:name = json_object_set_key($2:name, $3::text, $4::jsonb) WHERE "className"=$1' ,
908
908
[ className , 'schema' , 'indexes' , JSON . stringify ( existingIndexes ) ]
909
909
) ;
@@ -991,17 +991,17 @@ export class PostgresStorageAdapter implements StorageAdapter {
991
991
const values = [ className , ...valuesArray ] ;
992
992
993
993
debug ( qs , values ) ;
994
- return conn . task ( 'create-table' , function * ( t ) {
994
+ return conn . task ( 'create-table' , async ( t ) => {
995
995
try {
996
- yield self . _ensureSchemaCollectionExists ( t ) ;
997
- yield t . none ( qs , values ) ;
996
+ await self . _ensureSchemaCollectionExists ( t ) ;
997
+ await t . none ( qs , values ) ;
998
998
} catch ( error ) {
999
999
if ( error . code !== PostgresDuplicateRelationError ) {
1000
1000
throw error ;
1001
1001
}
1002
1002
// ELSE: Table already exists, must have been created by a different request. Ignore the error.
1003
1003
}
1004
- yield t . tx ( 'create-table-tx' , tx => {
1004
+ await t . tx ( 'create-table-tx' , tx => {
1005
1005
return tx . batch (
1006
1006
relations . map ( fieldName => {
1007
1007
return tx . none (
@@ -1019,8 +1019,8 @@ export class PostgresStorageAdapter implements StorageAdapter {
1019
1019
conn = conn || this . _client ;
1020
1020
const self = this ;
1021
1021
1022
- return conn . tx ( 'schema-upgrade' , function * ( t ) {
1023
- const columns = yield t . map (
1022
+ return conn . tx ( 'schema-upgrade' , async ( t ) => {
1023
+ const columns = await t . map (
1024
1024
'SELECT column_name FROM information_schema.columns WHERE table_name = $<className>' ,
1025
1025
{ className } ,
1026
1026
a => a . column_name
@@ -1036,7 +1036,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1036
1036
)
1037
1037
) ;
1038
1038
1039
- yield t . batch ( newColumns ) ;
1039
+ await t . batch ( newColumns ) ;
1040
1040
} ) ;
1041
1041
}
1042
1042
@@ -1050,10 +1050,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
1050
1050
debug ( 'addFieldIfNotExists' , { className, fieldName, type } ) ;
1051
1051
conn = conn || this . _client ;
1052
1052
const self = this ;
1053
- return conn . tx ( 'add-field-if-not-exists' , function * ( t ) {
1053
+ return conn . tx ( 'add-field-if-not-exists' , async ( t ) => {
1054
1054
if ( type . type !== 'Relation' ) {
1055
1055
try {
1056
- yield t . none (
1056
+ await t . none (
1057
1057
'ALTER TABLE $<className:name> ADD COLUMN $<fieldName:name> $<postgresType:raw>' ,
1058
1058
{
1059
1059
className,
@@ -1063,7 +1063,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1063
1063
) ;
1064
1064
} catch ( error ) {
1065
1065
if ( error . code === PostgresRelationDoesNotExistError ) {
1066
- return yield self . createClass (
1066
+ return await self . createClass (
1067
1067
className ,
1068
1068
{ fields : { [ fieldName ] : type } } ,
1069
1069
t
@@ -1075,13 +1075,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
1075
1075
// Column already exists, created by other request. Carry on to see if it's the right type.
1076
1076
}
1077
1077
} else {
1078
- yield t . none (
1078
+ await t . none (
1079
1079
'CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )' ,
1080
1080
{ joinTable : `_Join:${ fieldName } :${ className } ` }
1081
1081
) ;
1082
1082
}
1083
1083
1084
- const result = yield t . any (
1084
+ const result = await t . any (
1085
1085
'SELECT "schema" FROM "_SCHEMA" WHERE "className" = $<className> and ("schema"::json->\'fields\'->$<fieldName>) is not null' ,
1086
1086
{ className, fieldName }
1087
1087
) ;
@@ -1090,7 +1090,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1090
1090
throw 'Attempted to add a field that already exists' ;
1091
1091
} else {
1092
1092
const path = `{fields,${ fieldName } }` ;
1093
- yield t . none (
1093
+ await t . none (
1094
1094
'UPDATE "_SCHEMA" SET "schema"=jsonb_set("schema", $<path>, $<type>) WHERE "className"=$<className>' ,
1095
1095
{ path, type, className }
1096
1096
) ;
@@ -1120,9 +1120,9 @@ export class PostgresStorageAdapter implements StorageAdapter {
1120
1120
debug ( 'deleteAllClasses' ) ;
1121
1121
1122
1122
return this . _client
1123
- . task ( 'delete-all-classes' , function * ( t ) {
1123
+ . task ( 'delete-all-classes' , async ( t ) => {
1124
1124
try {
1125
- const results = yield t . any ( 'SELECT * FROM "_SCHEMA"' ) ;
1125
+ const results = await t . any ( 'SELECT * FROM "_SCHEMA"' ) ;
1126
1126
const joins = results . reduce ( ( list : Array < string > , schema : any ) => {
1127
1127
return list . concat ( joinTablesForSchema ( schema . schema ) ) ;
1128
1128
} , [ ] ) ;
@@ -1142,7 +1142,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
1142
1142
query : 'DROP TABLE IF EXISTS $<className:name>' ,
1143
1143
values : { className } ,
1144
1144
} ) ) ;
1145
- yield t . tx ( tx => tx . none ( helpers . concat ( queries ) ) ) ;
1145
+ await t . tx ( tx => tx . none ( helpers . concat ( queries ) ) ) ;
1146
1146
} catch ( error ) {
1147
1147
if ( error . code !== PostgresRelationDoesNotExistError ) {
1148
1148
throw error ;
@@ -1190,13 +1190,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
1190
1190
} )
1191
1191
. join ( ', DROP COLUMN' ) ;
1192
1192
1193
- return this . _client . tx ( 'delete-fields' , function * ( t ) {
1194
- yield t . none (
1193
+ return this . _client . tx ( 'delete-fields' , async ( t ) => {
1194
+ await t . none (
1195
1195
'UPDATE "_SCHEMA" SET "schema"=$<schema> WHERE "className"=$<className>' ,
1196
1196
{ schema, className }
1197
1197
) ;
1198
1198
if ( values . length > 1 ) {
1199
- yield t . none ( `ALTER TABLE $1:name DROP COLUMN ${ columns } ` , values ) ;
1199
+ await t . none ( `ALTER TABLE $1:name DROP COLUMN ${ columns } ` , values ) ;
1200
1200
}
1201
1201
} ) ;
1202
1202
}
@@ -1206,9 +1206,9 @@ export class PostgresStorageAdapter implements StorageAdapter {
1206
1206
// rejection reason are TBD.
1207
1207
getAllClasses ( ) {
1208
1208
const self = this ;
1209
- return this . _client . task ( 'get-all-classes' , function * ( t ) {
1210
- yield self . _ensureSchemaCollectionExists ( t ) ;
1211
- return yield t . map ( 'SELECT * FROM "_SCHEMA"' , null , row =>
1209
+ return this . _client . task ( 'get-all-classes' , async ( t ) => {
1210
+ await self . _ensureSchemaCollectionExists ( t ) ;
1211
+ return await t . map ( 'SELECT * FROM "_SCHEMA"' , null , row =>
1212
1212
toParseSchema ( { className : row . className , ...row . schema } )
1213
1213
) ;
1214
1214
} ) ;
0 commit comments