tuql

Automatically create a GraphQL server from a sqlite database

Github星跟蹤圖

tuql build status Coverage Status

Pronounced: Too cool

tuql is a simple tool that turns a sanely formatted sqlite database into a graphql endpoint. It tries to infer relationships between objects, currently supporting belongsTo, hasMany and belongsToMany. It also forms the basic mutations necessary to create, update, and delete objects, as well as assoicate many-to-many relationships.

Installing

npm install -g tuql

Using

tuql --db path/to/database.sqlite

You can also optionally set the port and enable graphiql:

tuql --db path/to/database.sqlite --port 8888 --graphiql

Or, you can use a sql file with statements to build up an in-memory database:

tuql --infile path/to/db_dump.sql --graphiql

If you'd like to print out the schema itself, use:

tuql --db path/to/database.sqlite --schema

Or send it to a file:

tuql --db path/to/database.sqlite --schema > schema.graphql

How it works

Imagine your sqlite schema looked something like this:, posts, users, categories, category_post, :-:, :-:, :-:, :-:, id  , id, id, category_id, user_id, username, title, post_id, title, body, tuql will automatically define models and associations, so that graphql queries like this will work right out of the box:

{
  posts {
    title
    body
    user {
      username
    }
    categories {
      title
    }
  }
}

tuql works one of two ways. It prefers to map your schema based on the foreign key information in your tables. If foreign keys are not present, tuql assumes the following about your schema in order to map relationships:

  1. The primary key column is named id or thing_id or thingId, where thing is the singular form of the table name. Example: For a table named posts, the primary key column should be named id, post_id or postId.
  2. Similarly, foreign key columns should be thing_id or thingId, where thing is the singular form of the associated table.
  3. For many-to-many associations, the table name should be in the form of foo_bar or bar_foo (ordering is not important). The columns should follow the same pattern as #2 above.

主要指標

概覽
名稱與所有者bradleyboy/tuql
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2017-11-20 02:43:15
推送於2021-06-06 17:14:12
最后一次提交2021-06-06 13:14:12
發布數0
用户参与
星數1.1k
關注者數23
派生數42
提交數72
已啟用問題?
問題數32
打開的問題數15
拉請求數7
打開的拉請求數0
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?