Socket
Socket
Sign inDemoInstall

ormgpt

Package Overview
Dependencies
78
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ormgpt

An ORM based on OpenAI that translates plain human language into SQL queries and executes them on a database.


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

ormGPT

An ORM based on OpenAI that translates plain human language into SQL queries and executes them on a database.

Currently supports database dialects: MySQL, PostgreSQL, and SQLite.

Supported languages: English, German, French, Spanish, Polish, Italian, Dutch, Portuguese, Ukrainian, Arabic, Chinese, Japanese, Korean, Turkish and many more.

ormgpt.query("give me post with id 1, all comments for this post and user information about author");

Generated query:

SELECT 
  p.id AS post_id, 
  p.title, 
  p.body, 
  c.id AS comment_id, 
  c.body AS comment_body, 
  u.username AS author_username, 
  u.email AS author_email 
FROM 
  posts p 
  JOIN comments c ON p.id = c.post_id 
  JOIN users u ON u.id = p.user_id 
WHERE 
  p.id = 1;

Response:

[
  {
    post_id: 1,
    title: 'Hello world!',
    body: 'This is my first post!',
    comment_id: 1,
    comment_body: 'Hello world!',
    author_username: 'test',
    author_email: 'test@example.com'
  }
]

./preview.gif

Installation

npm install ormgpt

# or

yarn add ormgpt

# or

pnpm add ormgpt

Usage

Prepare a database schema file, for example schema.sql. This file will be used to generate queries.

  const client = await createConnection({
    host: 'localhost',
    port: 3306,
    database: 'ormgpt',
    user: 'root',
    password: 'mysecretpassword',
  });

  const mysqlAdapter = new MysqlAdapter({
    client
  });

  const ormgpt = new ormGPT({
    apiKey: "OPENAI_API_KEY",
    schemaFilePath: "./example/schema.sql",
    dialect: "postgres",
    dbEngineAdapter: mysqlAdapter,
  });

  await ormgpt.query(
    "add new user with username 'test' and email 'test@example.com'",
  );
    
  const users = await ormgpt.query("get all users");
  console.log(users);

Adapters

MySQL

const client = await createConnection({
  host: 'localhost',
  port: 3306,
  database: 'ormgpt',
  user: 'root',
  password: 'mysecretpassword',
});

const mysqlAdapter = new MysqlAdapter({
  client
});

Postgres

const client = new Client({
  host: 'localhost',
  port: 5432,
  database: 'ormgpt',
  user: 'mysecretuser',
  password: 'mysecretpassword',
});
client.connect();

const postgresAdapter = new PostgresAdapter({
  client
});

SQLite

const sqliteAdapter = new SqliteAdapter({
  dbFilePath: "./example/db.sqlite",
});

Why?

In the last two years, I found ORMs to be new "days since the last javascript framework" in the JavaScript ecosystem. And since AI is a hot buzzword I decided to experiment a little to combine both and create an ORM that uses OpenAI to generate SQL queries. Please don't use this in production.

License

MIT

Keywords

FAQs

Last updated on 30 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc