Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[catalog] add import example #636

Open
HerringtonDarkholme opened this issue Jan 9, 2025 · 0 comments
Open

[catalog] add import example #636

HerringtonDarkholme opened this issue Jan 9, 2025 · 0 comments

Comments

@HerringtonDarkholme
Copy link
Member

// Import the MongoClient from the mongodb package
import { MongoClient } from 'mongodb';

// Connection URL and Database Name
const url = 'mongodb://localhost:27017';
const dbName = 'myDatabase';

async function run() {
    // Create a new MongoClient
    const client = new MongoClient(url);

    try {
        // Connect to the MongoDB server
        await client.connect();
        console.log('Connected successfully to MongoDB');

        // Select the database
        const db = client.db(dbName);

        // Select the collection
        const collection = db.collection('myCollection');

        // Query the collection
        const documents = await collection.find({}).toArray();
        console.log('Documents retrieved:', documents);
    } catch (err) {
        console.error('An error occurred:', err);
    } finally {
        // Close the connection
        await client.close();
        console.log('Connection closed');
    }
}

// Run the function
run();
rule:
  # we want to highlight the usage of our imported module
  # so the usage is what we are actually going to match on.
  # to check against the import we will traverse from the usage all the way to the root of the doc
  # and then down to the import statement


  # the usage
  kind: identifier
  pattern: $MOD
  
  # its relationship to the root
  inside:
    stopBy: end
    kind: program

    # and back down to the import statement
    has:
      stopBy: end # we allow going multiple levels deep though we expect imports to be children of the root
      kind: import_statement

      # and deeper into the import statement looking for the matching identifier
      has:
        stopBy: end
        kind: import_specifier
        pattern: $MOD # same pattern as the usage is enforced here
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant