{"id":43511,"library":"opensql","title":"OpenSql","description":"OpenSql is a promise-based ORM for MySQL, PostgreSQL, and Microsoft SQL Server, providing a unified API for database operations with TypeScript support. The current stable version is 2.2.2, released under MIT license. It features a simple configuration, promise-based queries, and multi-database support. Compared to alternatives like Sequelize or TypeORM, OpenSql focuses on a lightweight API and ease of use.","status":"active","version":"2.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/opensql-org/opensql","tags":["javascript","orm","opensql","mysql-orm","mysql","database","mssql","postresql","sql","typescript"],"install":[{"cmd":"npm install opensql","lang":"bash","label":"npm"},{"cmd":"yarn add opensql","lang":"bash","label":"yarn"},{"cmd":"pnpm add opensql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"MySQL driver for database connections","package":"mysql2","optional":false},{"reason":"PostgreSQL driver for database connections","package":"pg","optional":true},{"reason":"MS SQL Server driver for database connections","package":"mssql","optional":true}],"imports":[{"note":"Named export, not default. TypeScript types included.","wrong":"import OpenSql from 'opensql'","symbol":"OpenSql","correct":"import { OpenSql } from 'opensql'"},{"note":"Type for configuration object.","symbol":"Config","correct":"import { Config } from 'opensql'"},{"note":"Type for query results.","symbol":"QueryResult","correct":"import { QueryResult } from 'opensql'"}],"quickstart":{"code":"import { OpenSql } from 'opensql';\n\nconst config = {\n  host: process.env.DB_HOST ?? 'localhost',\n  port: parseInt(process.env.DB_PORT ?? '3306'),\n  user: process.env.DB_USER ?? 'root',\n  password: process.env.DB_PASSWORD ?? '',\n  database: process.env.DB_NAME ?? 'test'\n};\n\nconst db = new OpenSql(config);\n\nasync function main() {\n  try {\n    const result = await db.query('SELECT NOW() as currentTime');\n    console.log('Current time:', result[0].currentTime);\n  } catch (error) {\n    console.error('Query failed:', error);\n  } finally {\n    await db.end();\n  }\n}\n\nmain();","lang":"typescript","description":"Connects to MySQL using environment variables, runs a SELECT query, and logs the result."},"warnings":[{"fix":"Use `import { OpenSql } from 'opensql'` instead of `import OpenSql from 'opensql'`.","message":"In v2.0.0, the API changed from using default export to named export `OpenSql`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Access results as array elements, e.g., `result[0]`.","message":"The `query` method returns an array of rows, not a custom object.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Install `mysql2` for MySQL, `pg` for PostgreSQL, or `mssql` for SQL Server.","message":"Database drivers must be installed separately for each database type.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.2.2':31 'altern':52 'api':19,62 'base':7,43 'compar':50 'configur':40 'current':27 'databas':21,48,74 'eas':64 'featur':37 'focus':58 'javascript':67 'licens':35 'lightweight':61 'like':53 'microsoft':13 'mit':34 'mssql':75 'multi':47 'multi-databas':46 'mysql':10,71,73 'mysql-orm':70 'opensql':1,2,57,69 'oper':22 'orm':8,68,72 'postgresql':11 'postresql':76 'promis':6,42 'promise-bas':5,41 'provid':16 'queri':44 'releas':32 'sequel':54 'server':15 'simpl':39 'sql':14,77 'stabl':28 'support':25,49 'typeorm':56 'typescript':24,78 'unifi':18 'use':66 'version':29","created_at":"2026-06-05T17:00:09.011629+00:00","updated_at":"2026-06-05T17:00:09.011629+00:00","problems":[{"fix":"Use `import { OpenSql } from 'opensql'`.","cause":"Using default import with named export.","error":"TypeError: opensql_1.OpenSql is not a constructor"},{"fix":"Run `npm install mysql2`.","cause":"Missing MySQL driver dependency.","error":"Error: Cannot find module 'mysql2'"},{"fix":"Check that MySQL is running and that host/port are correct in config.","cause":"MySQL server not running or wrong host/port.","error":"Error: Connection refused: connect ECONNREFUSED 127.0.0.1:3306"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/opensql-org/opensql#readme","github":"https://github.com/opensql-org/opensql","docs":null,"changelog":null,"pypi":null,"npm":"opensql","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}