Skip to content

Commit

Permalink
Move client close to top level cli file (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF authored Oct 10, 2023
1 parent 94265c2 commit 8073d11
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 75 deletions.
2 changes: 2 additions & 0 deletions packages/generate/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ Run this command inside an EdgeDB project directory or specify the desired targe
}
} catch (e) {
exitWithError((e as Error).message);
} finally {
await client.close();
}
adapter.process.exit();
};
Expand Down
134 changes: 65 additions & 69 deletions packages/generate/src/edgeql-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,77 +88,73 @@ export async function generateQueryBuilder(params: {

const dir = new DirBuilder();

try {
// tslint:disable-next-line
console.log(`Introspecting database schema...`);

const [types, scalars, casts, functions, operators, globals, version] =
await Promise.all([
$.introspect.types(cxn),
$.introspect.scalars(cxn),
$.introspect.casts(cxn),
$.introspect.functions(cxn),
$.introspect.operators(cxn),
$.introspect.globals(cxn),
cxn.queryRequiredSingle<Version>(`select sys::get_version()`),
]);

const typesByName: Record<string, $.introspect.Type> = {};
for (const type of types.values()) {
typesByName[type.name] = type;

// skip "anytype" and "anytuple"
if (!type.name.includes("::")) continue;
}

const generatorParams: GeneratorParams = {
dir,
types,
typesByName,
casts,
scalars,
functions,
globals,
operators,
edgedbVersion: version,
};
generateRuntimeSpec(generatorParams);
generateCastMaps(generatorParams);
generateScalars(generatorParams);
generateObjectTypes(generatorParams);
generateFunctionTypes(generatorParams);
generateOperators(generatorParams);
generateSetImpl(generatorParams);
generateGlobals(generatorParams);

// TODO: Fix 'fts' module generation properly, for now we just disable
// output of this module
dir._modules.delete("fts");
dir._map.delete("modules/fts");
// -----------------

generateIndex(generatorParams);

// generate module imports

const importsFile = dir.getPath("imports");

importsFile.addExportStar("edgedb", { as: "edgedb" });
importsFile.addExportFrom({ spec: true }, "./__spec__", {
allowFileExt: true,
});
importsFile.addExportStar("./syntax", {
allowFileExt: true,
as: "syntax",
});
importsFile.addExportStar("./castMaps", {
allowFileExt: true,
as: "castMaps",
});
} finally {
await cxn.close();
// tslint:disable-next-line
console.log(`Introspecting database schema...`);

const [types, scalars, casts, functions, operators, globals, version] =
await Promise.all([
$.introspect.types(cxn),
$.introspect.scalars(cxn),
$.introspect.casts(cxn),
$.introspect.functions(cxn),
$.introspect.operators(cxn),
$.introspect.globals(cxn),
cxn.queryRequiredSingle<Version>(`select sys::get_version()`),
]);

const typesByName: Record<string, $.introspect.Type> = {};
for (const type of types.values()) {
typesByName[type.name] = type;

// skip "anytype" and "anytuple"
if (!type.name.includes("::")) continue;
}

const generatorParams: GeneratorParams = {
dir,
types,
typesByName,
casts,
scalars,
functions,
globals,
operators,
edgedbVersion: version,
};
generateRuntimeSpec(generatorParams);
generateCastMaps(generatorParams);
generateScalars(generatorParams);
generateObjectTypes(generatorParams);
generateFunctionTypes(generatorParams);
generateOperators(generatorParams);
generateSetImpl(generatorParams);
generateGlobals(generatorParams);

// TODO: Fix 'fts' module generation properly, for now we just disable
// output of this module
dir._modules.delete("fts");
dir._map.delete("modules/fts");
// -----------------

generateIndex(generatorParams);

// generate module imports

const importsFile = dir.getPath("imports");

importsFile.addExportStar("edgedb", { as: "edgedb" });
importsFile.addExportFrom({ spec: true }, "./__spec__", {
allowFileExt: true,
});
importsFile.addExportStar("./syntax", {
allowFileExt: true,
as: "syntax",
});
importsFile.addExportStar("./castMaps", {
allowFileExt: true,
as: "castMaps",
});

const initialFiles = new Set(await walk(outputDir));
const written = new Set<string>();

Expand Down
7 changes: 1 addition & 6 deletions packages/generate/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ export async function runInterfacesGenerator(params: {

// tslint:disable-next-line
console.log(`Introspecting database schema...`);
let types: $.introspect.Types;
try {
types = await $.introspect.types(client);
} finally {
client.close();
}
const types = await $.introspect.types(client);

const generatorParams = {
dir,
Expand Down

0 comments on commit 8073d11

Please sign in to comment.