Attributes allows you to easily query a database (currently PostgreSQL or Sqlite3) for its schema — columns or attributes — and get their properties such as name, type and default value, in a common format.
Note: Must.js will follow the semantic versioning starting from v1.0.0.
npm install attributes
Each database has its own function you can call passing it the connection to that database and the table name you'd like to get attributes for.
For example, with Sqlite3, just initialize the
Database object and pass that
var Sqlite3 =var db = "database.sqlite3"var Attributes =Attributes
For now, you'll have to know the table name in advance.
Given the following table:
("name" VARCHAR(255) DEFAULT 'Tiger' NOT NULL,"handicap" INTEGER DEFAULT 52 NOT NULL,"created_at" DATETIME)
var Pg =Pgdefaultsdatabase = "golf"var db =dbvar Attributes =Attributes
Will call the callback with the following object for
name: null: false type: String default: "Tiger" limit: 255handicap: null: false type: Number default: 52 limit: nullupdated_at: null: true type: Date default: null limit: null
For extended documentation, please see the Attributes API Documentation.
Attributes is released under a Lesser GNU Affero General Public License, which in summary means:
For more convoluted language, see the