Um ORM baseado no OpenAI que traduz a linguagem humana simples em consultas SQL e as executa em um banco de dados.
Atualmente, suporta dialetos de banco de dados: MySQL, PostGresQL e SQLite.
Línguas apoiadas: inglês, alemão, francês, espanhol, polonês, italiano, holandês, português, ucraniano, árabe, chinês, japonês, coreano, turco e muito mais.
ormgpt.query( " give me post with id 1, all comments for this post and user information about author " ) ;Consulta gerada:
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 ;Resposta:
[
{
post_id : 1 ,
title : 'Hello world!' ,
body : 'This is my first post!' ,
comment_id : 1 ,
comment_body : 'Hello world!' ,
author_username : 'test' ,
author_email : '[email protected]'
}
] 
npm install ormgpt
# or
yarn add ormgpt
# or
pnpm add ormgpt Prepare um arquivo de esquema de banco de dados, por exemplo, schema.sql . Este arquivo será usado para gerar consultas.
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 '[email protected]'" ,
) ;
const users = await ormgpt . query ( "get all users" ) ;
console . log ( users ) ;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" ,
} ) ;Nos últimos dois anos, achei o ORMS "dias desde a última estrutura JavaScript" no ecossistema JavaScript. E como a IA é uma palavra de palavra quente, decidi experimentar um pouco para combinar os dois e criar um ORM que usa o OpenAI para gerar consultas SQL. Por favor, não use isso na produção.
Mit