1.1.0 • Public • Published



    Generates GRDB Records from SQLite CREATE TABLE


    $ [sudo] npm install grdb-record-generator -g

    What it does?

    Transforms this:

    CREATE TABLE user (
        name TEXT NULL DEFAULT '',
        surname TEXT NULL DEFAULT '',
        email TEXT NOT NULL,
        image TEXT NULL DEFAULT '',
        wizard_status INTEGER NOT NULL DEFAULT 0,
        color TEXT

    into UserModel.swift (Swift 4):

    import Foundation
    import GRDB
    class UserModel: Record {
        var _id: Int64?
        var name: String? = ""
        var surname: String? = ""
        var email: String
        var image: String? = ""
        var wizard_status: Int64 = 0
        var color: String?
        static let createTable = "CREATE TABLE \(databaseTableName) (" +
                "_id INTEGER NOT NULL PRIMARY KEY, " +
                "name TEXT NULL DEFAULT '', " +
                "surname TEXT NULL DEFAULT '', " +
                "email TEXT NOT NULL, " +
                "image TEXT NULL DEFAULT '', " +
                "wizard_status INTEGER NOT NULL DEFAULT 0, " +
                "color TEXT " +
                ") "
        override class var databaseTableName: String {
            return "user"
        enum Columns {
            static let _id = Column("_id")
            static let name = Column("name")
            static let surname = Column("surname")
            static let email = Column("email")
            static let image = Column("image")
            static let wizard_status = Column("wizard_status")
            static let color = Column("color")
        init(email: String) {
   = email
        required init(row: Row) {
            _id = row[Columns._id]
            name = row[]
            surname = row[Columns.surname]
            email = row[]
            image = row[Columns.image]
            wizard_status = row[Columns.wizard_status]
            color = row[Columns.color]
            super.init(row: row)
        override func encode(to container: inout PersistenceContainer) {
            container[Columns._id] = _id
            container[] = name
            container[Columns.surname] = surname
            container[] = email
            container[Columns.image] = image
            container[Columns.wizard_status] = wizard_status
            container[Columns.color] = color


    Create an sql file with a single CREATE TABLE statement in it (e.g. yourfile.sql), and execute:

    grdb-record-generator yourfile.sql /outputdir

    and you will get the resulting Swift model in the specified output directory.


    The generator has some configuration options. It has been a choice to not add them as console parameters, to keep the usage simple and straightforward.


    • new_line_character: Defines the character to use as a new line character for the output swift files. Defaults to \n.
    • indentation: Defines how many spaces to use for a single indentation level of the output swift code. Defaults to 4.
    • add_create_table: if you set this to true, in the generated swift file you will also get a static let createTable with the needed SQL to create the table. Defaults to true.

    Where is the configuration file?

    When you install the module locally, you can find the configuration at this path ./node_modules/grdb-record-generator/config.js

    When you install the module globally, the configuration resides in the global node_modules directory. For example, on a macOS, the config.js is usually located at this path: /usr/local/lib/node_modules/grdb-record-generator/config.js. You will need root permissions to modify it.

    For more info, please check:

    How can I preserve my global config after updates?

    [sudo] cp /usr/local/lib/node_modules/grdb-record-generator/config.js /tmp/grdbconfig
    [sudo] npm remove grdb-record-generator -g
    [sudo] npm install grdb-record-generator -g
    [sudo] cp /tmp/grdbconfig /usr/local/lib/node_modules/grdb-record-generator/config.js

    sudo is optional and depends on how you have installed nodejs.


    Copyright (C) 2017-2019 Aleksandar Gotev
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.


    npm i grdb-record-generator

    DownloadsWeekly Downloads






    Unpacked Size

    30.2 kB

    Total Files


    Last publish


    • gotev