Skip to content

Commit

Permalink
typing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 16, 2025
1 parent d7b15ab commit 937eee8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion typescript-express-reviews/src/models/mongoose.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose';
import { driver } from 'stargate-mongoose';

const mongooseInstance = new mongoose.Mongoose().setDriver(driver);
const mongooseInstance = mongoose.setDriver(driver);
mongooseInstance.set('autoCreate', false);
mongooseInstance.set('autoIndex', false);

Expand Down
10 changes: 4 additions & 6 deletions typescript-express-reviews/src/seed/dropCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ dropCollections().catch(err => {
async function dropCollections() {
await connect();

const connection: driver.Connection = mongoose.connection as unknown as driver.Connection;

const collections = await connection.listCollections();
const collections = await mongoose.connection.listCollections();
for (const collection of collections) {
console.log('Dropping collection', collection.name);
await connection.dropCollection(collection.name);
await mongoose.connection.dropCollection(collection.name);
}

const tables = await connection.listTables();
const tables = await mongoose.connection.listTables();
for (const table of tables) {
console.log('Dropping table', table.name);
await connection.dropTable(table.name);
await mongoose.connection.dropTable(table.name);
}

console.log('Done');
Expand Down
21 changes: 9 additions & 12 deletions typescript-express-reviews/src/seed/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,20 @@ run().catch(err => {

async function run() {
await connect();

const connection: driver.Connection = mongoose.connection as unknown as driver.Connection;

if (!process.env.IS_ASTRA) {
await connection.createNamespace(connection.namespace as string);
await mongoose.connection.createNamespace(mongoose.connection.namespace as string);
}

if (process.env.DATA_API_TABLES) {
await connection.dropTable('authentications');
await connection.dropTable('reviews');
await connection.dropTable('users');
await connection.dropTable('vehicles');
await mongoose.connection.dropTable('authentications');
await mongoose.connection.dropTable('reviews');
await mongoose.connection.dropTable('users');
await mongoose.connection.dropTable('vehicles');

await connection.createTable('authentications', tableDefinitionFromSchema(Authentication.schema));
await connection.createTable('reviews', tableDefinitionFromSchema(Review.schema));
await connection.createTable('users', tableDefinitionFromSchema(User.schema));
await connection.createTable('vehicles', tableDefinitionFromSchema(Vehicle.schema));
await mongoose.connection.createTable('authentications', tableDefinitionFromSchema(Authentication.schema));
await mongoose.connection.createTable('reviews', tableDefinitionFromSchema(Review.schema));
await mongoose.connection.createTable('users', tableDefinitionFromSchema(User.schema));
await mongoose.connection.createTable('vehicles', tableDefinitionFromSchema(Vehicle.schema));
} else {
const existingCollections = await mongoose.connection.listCollections()
.then(collections => collections.map(c => c.name));
Expand Down

0 comments on commit 937eee8

Please sign in to comment.