Skip to content

Instantly share code, notes, and snippets.

Avatar

Natalie Smith natmegs

View GitHub Profile
View schema.json
{
"$schema": "http:\/\/json-schema.org\/schema#",
"definitions": {
"pathType": {
"type": "string",
"pattern": "^([a-z0-9]([a-z0-9-]*[a-z0-9]+)*)([.][a-z0-9]([a-z0-9-]*[a-z0-9]+)*)*$",
"minLength": 1
}
},
"type": "object",
@natmegs
natmegs / example.js
Created May 1, 2018
Querying database using Sequelize
View example.js
const models = require('../models');
models.user.findOne({ where: {id: id} })
.then(user => {
// Do something with User instance
});
models.user.create(data)
.then((newUser) => {
// Do something with User instance
@natmegs
natmegs / www
Created May 1, 2018
Database synchronization in bin/www
View www
const models = require('../models');
models.sequelize.sync().then(function() {
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
});
@natmegs
natmegs / index.js
Created May 1, 2018
Consolidate all models (in models folder)
View index.js
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const config = require('../config/db');
let db = {};
let sequelize = new Sequelize(config.database, config.username, config.password, config.options);
fs
.readdirSync(__dirname)
@natmegs
natmegs / user.js
Created May 1, 2018
Define User model (in models folder)
View user.js
module.exports = function(sequelize, Sequelize) {
const User = sequelize.define('user', {
id: {
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
firstname: {
type: Sequelize.STRING,
notEmpty: true
@natmegs
natmegs / app.js
Created May 1, 2018
Connect to SQL Server and Database
View app.js
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'SQL.server.address.database.net',
dialect: 'mssql',
dialectOptions: {
encrypt: true;
}
});
sequelize
@natmegs
natmegs / app.component.ts
Created Jan 10, 2018
ViewChild vs ViewChildren
View app.component.ts
@ViewChild(HelloComponent) hello: HelloComponent;
@ViewChildren(HelloComponent) hellos: QueryList<HelloComponent>;
ngAfterViewInit() {
console.log(this.hello);
console.log(this.hellos);
}
View app.component.ts
@ViewChild(HelloComponent) hello: HelloComponent;
@ViewChild('template') template: TemplateRef<any>;
@ViewChild('element') element: ElementRef;
@ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef;
ngAfterViewInit() {
console.log(this.hello);
console.log(this.template);
console.log(this.element);
console.log(this.container);
View app.template.html
<hello name="Jelly Donut"></hello>
<hello name="Old Fashioned Glazed"></hello>
<ng-container #container>
This is a container
</ng-container>
<ng-template #template>
This is a template
@natmegs
natmegs / app.template.html
Created Jan 8, 2018
Using SomeComponent with projected content
View app.template.html
<some-component>
<h3>I am the projected content!</h3>
</some-component>
You can’t perform that action at this time.