npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grdb-record-generator

v1.1.0

Published

Generates GRDB record in swift from CREATE TABLE statements

Downloads

25

Readme

GRDB-Record-Generator

NPM

Generates GRDB Records from SQLite CREATE TABLE

Setup

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

What it does?

Transforms this:

CREATE TABLE user (
    _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
)

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) {
        self.email = email
        super.init()
    }

    required init(row: Row) {
        _id = row[Columns._id]
        name = row[Columns.name]
        surname = row[Columns.surname]
        email = row[Columns.email]
        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[Columns.name] = name
        container[Columns.surname] = surname
        container[Columns.email] = email
        container[Columns.image] = image
        container[Columns.wizard_status] = wizard_status
        container[Columns.color] = color
    }

}

Usage

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.

Configuration

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.

Options

  • 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: https://stackoverflow.com/a/5926706

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.

License

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

   http://www.apache.org/licenses/LICENSE-2.0

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.